package mnc.game.tifo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

import javax.microedition.khronos.opengles.GL10;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Message;
import android.view.KeyEvent;
import bayaba.engine.lib.ButtonObject;
import bayaba.engine.lib.ButtonType;
import bayaba.engine.lib.Font;
import bayaba.engine.lib.GameInfo;
import bayaba.engine.lib.GameObject;
import bayaba.engine.lib.Project;
import bayaba.engine.lib.Sprite;
import bayaba.engine.lib.UITool;

public class GameMain 
{
	// 블럭의 움직임 형태 정의
	static class Const
	{
		static final int STOP 	= 0;
		static final int LEFT 	= 1;
		static final int RIGHT 	= 2;
		static final int UP 	= 3;
		static final int DOWN 	= 4;
		static final int FALL	= 5;
		static final int DEAD	= 6;
		static final int EFFECT	= 7;
		static final int READY	= 8;
		static final int DIVE	= 9;
		static final int PUSH	= 10;
	}
	static class UIQuitClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	POPUP_001		=	1;
			static final int	ONE_CLICK_002		=	2;
			static final int	ONE_CLICK_003		=	3;
		}

	}

	
	static class UINoticeClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	POPUP_001		=	1;
			static final int	ONE_CLICK_002		=	2;
			static final int	ONE_CLICK_003		=	3;
		}
	}
	
	
	static class UIFriendRankingClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	POPUP_001		=	1;
			static final int	POPUP_002		=	2;
			static final int	POPUP_003		=	3;
			static final int	POPUP_004		=	4;
			static final int	POPUP_005		=	5;
			static final int	ONE_CLICK_006		=	6;
			static final int	ONE_CLICK_007		=	7;
			static final int	ONE_CLICK_008		=	8;
			static final int	ONE_CLICK_009		=	9;
			static final int	ONE_CLICK_010		=	10;
			static final int	POPUP_011		=	11;
			static final int	POPUP_012		=	12;
			static final int	ONE_CLICK_013		=	13;
		}

	}


	static class UISettingClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	ONE_CLICK_001		=	1;
			static final int	ONE_CLICK_002		=	2;
			static final int	ONE_CLICK_003		=	3;
		}

	}
	static class UIFriend_InVitClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	POPUP_001		=	1;
			static final int	ONE_CLICK_002		=	2;
		}

	}
	static class UITimeBuyClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	POPUP_001		=	1;
			static final int	POPUP_002		=	2;
			static final int	POPUP_003		=	3;
			static final int	POPUP_004		=	4;
			static final int	POPUP_005		=	5;
			static final int	POPUP_006		=	6;
			static final int	POPUP_007		=	7;
			static final int	ONE_CLICK_008		=	8;
			static final int	ONE_CLICK_009		=	9;
			static final int	ONE_CLICK_010		=	10;
			static final int	ONE_CLICK_011		=	11;
			static final int	ONE_CLICK_012		=	12;
			static final int	ONE_CLICK_013		=	13;
			static final int	ONE_CLICK_014		=	14;
		}

	}

	static class UITifoBuyClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	POPUP_001		=	1;
			static final int	POPUP_002		=	2;
			static final int	POPUP_003		=	3;
			static final int	POPUP_004		=	4;
			static final int	POPUP_005		=	5;
			static final int	POPUP_006		=	6;
			static final int	POPUP_007		=	7;
			static final int	ONE_CLICK_008		=	8;
			static final int	ONE_CLICK_009		=	9;
			static final int	ONE_CLICK_010		=	10;
			static final int	ONE_CLICK_011		=	11;
			static final int	ONE_CLICK_012		=	12;
			static final int	ONE_CLICK_013		=	13;
			static final int	ONE_CLICK_014		=	14;
		}

	}
	static class UIResultClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	POPUP_001		=	1;
			static final int	POPUP_002		=	2;
			static final int	POPUP_003		=	3;
			static final int	POPUP_004		=	4;
			static final int	POPUP_005		=	5;
			static final int	ONE_CLICK_006		=	6;
		}

	}	

	static class UIAlertClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	ONE_CLICK_001		=	1;
		}

	}
	static class UIDataChkClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	ONE_CLICK_001		=	1;
			static final int	ONE_CLICK_002		=	2;
			static final int	POPUP_003		=	3;
		}

	}
	static class ULoginClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	POPUP_001		=	1;
			static final int	ONE_CLICK_002		=	2;
			static final int	ONE_CLICK_003		=	3;
			static final int	POPUP_004		=	4;
		}

	}

	static class UIHelpClass
	{
		static class Group0
		{
			static final int	POPUP_000		=	0;
			static final int	POPUP_001		=	1;
			static final int	POPUP_002		=	2;
			static final int	POPUP_003		=	3;
			static final int	POPUP_004		=	4;
			static final int	POPUP_005		=	5;
			static final int	POPUP_006		=	6;
			static final int	POPUP_007		=	7;
			static final int	ONE_CLICK_008		=	8;
		}

	}
	
	public GL10 mGL = null; // OpenGL 객체
	public Context MainContext;
	public Random MyRand = new Random();	
	public GameInfo gInfo; // 게임 환경 설정용 클래스 : MainActivity에 선언된 것을 전달 받는다.
	public float TouchX, TouchY;
	public int CurLayer = 0;
	public Project stage; 
    
	public GameObject Target = null; 
	public GameObject energy = null;
	public Sprite effect = new Sprite();
	public Sprite choose = new Sprite();
	public Sprite bomb   = new Sprite();
	public Sprite water_cha  = new Sprite();
	public Sprite light  = new Sprite();
	public Sprite preci_bomb  = new Sprite();
	public Sprite com_logo  = new Sprite(); 
	public Sprite cartoon   = new Sprite();
	public Sprite gameMain_logo  = new Sprite();
	public Sprite Point = new Sprite();   // 점수   스프라이트 객체
	public Sprite apply = new Sprite();   // 동의 
	public Sprite setting = new Sprite(); // 환경설정  
	public Sprite key = new Sprite();     // 스테이즈 버튼   
	public Sprite map = new Sprite();     // 맵 버튼   
	public Sprite score_ovr = new Sprite();  //    
	public Sprite result = new Sprite();     // 결과  
	public Sprite fy_meet_bk = new Sprite(); // 가족상봉
	public Sprite fy_meet    = new Sprite();
	public Sprite fire       = new Sprite(); // 폭죽
	public Sprite item       = new Sprite(); // 하트를 표시하기 위함 
	public Sprite cartoon_button  = new Sprite(); // 만화의 버튼  
	public Sprite family     = new Sprite();
	public Sprite t_store    = new Sprite();
	public Sprite copywrite  = new Sprite();
	
	public UITool QuitUI = new UITool();          // Quit
	public UITool NoticeUI = new UITool();        // 공지사항
	public UITool FriendRankingUI = new UITool(); // 친구순위
	public UITool SettingUI = new UITool();       // 환경설정
	public UITool Friend_InVitUI = new UITool();  // 친구초대
	public UITool TimeBuyUI = new UITool();       // TimeBuy (Store)
	public UITool TifoBuyUI = new UITool();       // TifoBuy 의 생명을 구매 
	public UITool ResultUI  = new UITool();       // 점수판  
	public UITool AlterUI  = new UITool();        // 알림   
	public UITool DataChkUI = new UITool();       // 데이터 동의 체크 
	public UITool LoginUI = new UITool();         // 로그인 동의 체크 
	public UITool HelpUI  = new UITool();         // 도움말 

	
	public int SndBuff[] = new int [6];
	public SoundPool SndPool;
	private boolean bGameOver = false;
	private ArrayList<GameObject> Game = new ArrayList<GameObject>(); // 불꽃 이펙트 등을 저장할 리스트
	
	public int GameMode = -1, StageNum = 0, pCount, Score; // GameMode는 현재 게임 화면 상태, StageNum은 스테이지 번호, pCount는 하트 갯수, Score는 현재 점수
	public int endJob = 0;
	boolean Moving = false;
	Font font = new Font();
	private long StartTimer = 0;
	private long StartGameTimer = 0;
	public byte StageData[] = new byte [100]; // 스테이지 클리어 상태를 저장하기 위한 배열
	public int BackKey = 0; // 백키가 눌렸을때 처리용 변수 (Eggman에서 설정)
	public float distance = 35.0f;
	public float x1,x2,y1,y2;
	public GameObject Temp1 = new GameObject();
	public GameObject Temp2 = new GameObject();
	private int gebukMontion = 0;
	private boolean left_right = false;
	public  float OldX, OldY;
	public  int FirstValChk = 0;
    public  int slideYn = 0;
    public boolean 	bSpider = false;
    public int pre_status = 0;
    public MediaPlayer Back_Music; // 음악을 연주하기 위한 객체
	public boolean Pause_Back_Music = false;
	private int CartoonNum = 1;
	public int pre_pointNum = 0;
	public int pre_hartNum  = 0;
	private int map_range[][] = {{0,10},
			                     {11,20},
			                     {21,25},
			                     {26,30}};
	private int start = 0;
	private int end = 0;
	public int tifoCount = 5;   // 티포의 갯수 
	public int timeCount = 1;   // 타임 갯수
	public int hartNum   = 0;   // 하트 점수 
	public int pointNum  = 0;   // 게임 점수 
	public String message = "";
	private int totalNum = 0;
	
	private DBTifoData  mDBTifoData;
	public  boolean bNotice = false;
	boolean bFriendRanking = false;
	boolean bFirst = false;
	boolean over = false;
	public  int outtime = 120;   /// 기존 시간 
	private boolean requestTstoreAuth = false;
	private boolean fanfare = false;
	private boolean dead = false;
	private int FamilyNum = 1;
	private boolean  invokeTstoreJoinPage = false;
	private boolean notice = false;
	public  boolean requestPBFriendRankingList = false;
    private boolean bStart = false;
    private boolean version = false;
    private int motion = 0;
    private float f = 0f;
    
	public int currentLevel = 4;  // 현재 게임을 할수 있는 stageNum;
	
	public ArrayList<ButtonObject>  Button = new ArrayList<ButtonObject>();
	public ArrayList<ButtonObject>  MapButton = new ArrayList<ButtonObject>();
	public ArrayList<ButtonObject>  LawButton = new ArrayList<ButtonObject>();
	public ArrayList<ButtonObject>  ApplyButton = new ArrayList<ButtonObject>();
	public ArrayList<ButtonObject>  RankingButton = new ArrayList<ButtonObject>();
	public ArrayList<ButtonObject>  RankingSendButton = new ArrayList<ButtonObject>();
	public ArrayList<ButtonObject>  InVitButton = new ArrayList<ButtonObject>();
	public ArrayList<ButtonObject>  InVitSendButton = new ArrayList<ButtonObject>();
	public ArrayList<ButtonObject>  SkipButton = new ArrayList<ButtonObject>();
	public ArrayList<ButtonObject>  NextButton = new ArrayList<ButtonObject>();
	
	
	Tifo Tifo;
	
	ButtonObject OverButton = new ButtonObject();
	ButtonObject GameOverButton = new ButtonObject();
	ButtonObject TimeOverButton = new ButtonObject();
	
	public GameMain( Tifo context, GameInfo info)
	{
		MainContext = context;
		this.Tifo = context;
		gInfo = info;
		
    	SndPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
    	SndBuff[0] = SndPool.load( MainContext, R.raw.move, 0 );    // 이동
    	SndBuff[1] = SndPool.load( MainContext, R.raw.clear, 0 );   // 아이템 먹을때 
       	SndBuff[2] = SndPool.load( MainContext, R.raw.explode, 0 );
       	SndBuff[3] = SndPool.load( MainContext, R.raw.dead, 0 );    // 티포 죽을때 
       	SndBuff[4] = SndPool.load( MainContext, R.raw.fanfare, 0 ); // 팡파레  
       	SndBuff[5] = SndPool.load( MainContext, R.raw.flash, 0 );   // 번개 맞을때   
		for ( int i = 0; i < 100; i++ ) StageData[i] = 0;           // 스테이지 데이터 초기화
		

		Back_Music = MediaPlayer.create(MainContext, R.raw.back_game);
		Back_Music.setLooping(true);   
		if(Tifo.back_sound.equals("Y")) Back_Music.start();
		
		mDBTifoData = new DBTifoData(context);
	}


	public void PlaySound( int num )
	{
		SndPool.play( SndBuff[num], 1f, 1f, 0, 0, 1f );
	}
	
	public void LoadCompanyLogo() {
		t_store.LoadSprite(mGL, MainContext, "t_store.spr");
		copywrite.LoadSprite(mGL, MainContext, "copywriter.spr");
		com_logo.LoadSprite(mGL, MainContext, "com_logo.spr");
		gameMain_logo.LoadSprite(mGL, MainContext, "game_main.spr");
		LoadFriendInVit();
		LoadQuitUI();
		
		LoadAlter();
		LoadFamily();
		
		LoadDataChk();
	}

	public void LoadHelp() {
		HelpUI.LoadUI( mGL, MainContext, "help.ui" ); 
		HelpUI.AddGroup( 0, 0 );
		
	}
	
	public void LoadDataChk() {
		DataChkUI.LoadUI( mGL, MainContext, "data_chk.ui" ); 
		DataChkUI.AddGroup( 0, 0 );
		
	}
	public void LoadFire() {
		fire.LoadSprite(mGL, MainContext, "fire.spr");
	}
	
	public void LoadFamily() {
		family.LoadSprite(mGL, MainContext, "family.spr");
	}
    public void LoadAlter() {
		AlterUI.LoadUI( mGL, MainContext, "alter.ui" ); // UI 파일을 로드한다.
		AlterUI.AddGroup( 0, 0 );
    	
    }
	/**
	 * 친구초대 
	 */
	public void LoadFriendInVit() {
		Friend_InVitUI.LoadUI( mGL, MainContext, "friend_invit.ui" ); // UI 파일을 로드한다.
		Friend_InVitUI.AddGroup( 0, 0 );
	}
	
	public void LoadTimeBuy() {
		TimeBuyUI.LoadUI( mGL, MainContext, "time_buy.ui" ); // UI 파일을 로드한다.
		TimeBuyUI.AddGroup( 0, 0 );
	}
	
	/**
	 * 티포의 생명을 사이버머니로 구매 
	 */
	public void LoadTifoBuy() {
		TifoBuyUI.LoadUI( mGL, MainContext, "tifo_buy.ui" ); // UI 파일을 로드한다.
		TifoBuyUI.AddGroup( 0, 0 );
	}
	public void LoadResult() {
		ResultUI.LoadUI( mGL, MainContext, "result.ui" ); // UI 파일을 로드한다.
		ResultUI.AddGroup( 0, 0 );
		
		Point.LoadSprite( mGL, MainContext, "ranking.spr" );   // 숫자 sprite 

	}

	public void DataSetFriendInVit() {
		int index1 = Friend_InVitUI.UIList.size(); // 마지막 ButtonObject ArrayList의 인덱스 번호를 저장해둔다.

		Friend_InVitUI.CreateListView( gInfo, Friend_InVitUI.Get(0, UIFriend_InVitClass.Group0.POPUP_000), Friend_InVitUI.Get(0, UIFriend_InVitClass.Group0.POPUP_000).pattern, ButtonType.TYPE_UPDOWN_LIST, 4, 0, Tifo.mFriendInVit.size(), 45, 95 );
		int x1 = 0;
		InVitButton.clear();
		InVitSendButton.clear();
		
		for ( int i = index1; i <  Friend_InVitUI.UIList.size(); i++ )
		{
			Friend_InVitUI.UIList.get(i).SetText(0, 130, 20, 0, 0, 0, 25, Tifo.mFriendInVit.get(x1).get("name") , 200, 60);
			////////////////// 대표이미지 ///////////////
			ButtonObject Button1 = new ButtonObject();
			if(Tifo.mFriendInVit_img.get(x1) != null) {
				Sprite img = new Sprite(); 
				img.LoadBitmap(mGL, MainContext, Tifo.mFriendInVit_img.get(0));
				Button1.SetButton(img, ButtonType.TYPE_ONE_CLICK, 0, 100, 155+(x1*95), 0);
			} else {
				Button1.SetButton(Point, ButtonType.TYPE_ONE_CLICK, 0, 160, 105+(x1*95), 12);
			}
			Button1.SetLinkTo(Friend_InVitUI.UIList.get(i));
			InVitButton.add(Button1);

			///////////////// 메세지 전송 /////////////////
			ButtonObject Button2 = new ButtonObject();
			Button2.SetButton(Friend_InVitUI.Get(0, UIFriend_InVitClass.Group0.POPUP_000).pattern, ButtonType.TYPE_ONE_CLICK, 0, 520, 140+(x1*95), 1);
			Button2.SetLinkTo(Friend_InVitUI.UIList.get(i));
			InVitSendButton.add(Button2);

			x1++;
		}	
	}
	/**
	 * Quit
	 */
	public void LoadQuitUI() {
		setting.LoadSprite(mGL, MainContext, "setting.spr");
		QuitUI.LoadUI( mGL, MainContext, "quit.ui" ); // UI 파일을 로드한다.
		QuitUI.AddGroup( 0, 0 );
	}
	
	/**
	 * 환경설정 
	 */
	public void LoadSettingUI() {
		SettingUI.LoadUI( mGL, MainContext, "setting.ui" ); // UI 파일을 로드한다.
		SettingUI.AddGroup( 0, 0 );
		
		for ( int i = 0; i < SettingUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if ( SettingUI.UIList.get(i).index == UISettingClass.Group0.ONE_CLICK_001 )     
			{
				if(Tifo.back_sound.equals("Y")) {
				    SettingUI.UIList.get(i).motion = 1;
				} else {
				    SettingUI.UIList.get(i).motion = 3;
 				}
			}

				
			if ( SettingUI.UIList.get(i).index == UISettingClass.Group0.ONE_CLICK_002 )  // effect sound
			{
				if(Tifo.effect_sound.equals("Y")) {
				    SettingUI.UIList.get(i).motion = 2;
	 			} else { 
				    SettingUI.UIList.get(i).motion = 4;
	 		    }	
			}
		}

	}

	/**
	 * 공지사항 
	 */
	public void LoadNoticeUI() {
		NoticeUI.LoadUI( mGL, MainContext, "notice.ui" ); // UI 파일을 로드한다.
		NoticeUI.AddGroup( 0, 0 );
		if(Tifo.noticeBm != null) {
			Sprite img = new Sprite(); 
			img.LoadBitmap(mGL, MainContext, Tifo.noticeBm);
			NoticeUI.CreateListView( gInfo, NoticeUI.Get(0, UINoticeClass.Group0.POPUP_000), img, ButtonType.TYPE_UPDOWN_LIST, 0, 0, 1, 45, 95 );
		}
	}

	/**
	 * 친구순위 
	 */
	
	public void LoadWeekRanking() {
		LoadSettingUI();
		result.LoadSprite(mGL, MainContext, "result.spr");
		
		Point.LoadSprite( mGL, MainContext, "ranking.spr" );   // 숫자 sprite 
		
		FriendRankingUI.LoadUI( mGL, MainContext, "ranking.ui" ); // UI 파일을 로드한다.
		FriendRankingUI.AddGroup( 0, 0 );
		int index1 = FriendRankingUI.UIList.size(); // 마지막 ButtonObject ArrayList의 인덱스 번호를 저장해둔다.

		FriendRankingUI.CreateListView( gInfo, FriendRankingUI.Get(0, UIFriendRankingClass.Group0.POPUP_000), FriendRankingUI.Get(0, UIFriendRankingClass.Group0.POPUP_000).pattern, ButtonType.TYPE_UPDOWN_LIST, 1, 0, Tifo.mFriendRanking.size(), 50, 105 );
		int x1 = 0;
		RankingButton.clear();
		RankingSendButton.clear();
		
		for ( int i = index1; i <  FriendRankingUI.UIList.size(); i++ )
		{
			FriendRankingUI.UIList.get(i).SetText(0, 130, 20, 0, 0, 0, 25, Tifo.mFriendRanking.get(x1).get("name") , 200, 60);
			FriendRankingUI.UIList.get(i).SetText(1, 140, 55, 0, 0, 0, 20, Tifo.mFriendRanking.get(x1).get("ranking") , 200, 60);
			FriendRankingUI.UIList.get(i).SetText(2, 300, 45, 0, 0, 0, 20, Tifo.mFriendRanking.get(x1).get("point") , 200, 60);

			////////////////// 대표이미지 ///////////////
			ButtonObject Button1 = new ButtonObject();
			if(Tifo.mFriendRanking_img.size() > x1) {
				if(Tifo.mFriendRanking_img.get(x1) != null) {
					try {
						Sprite img = new Sprite(); 
						img.LoadBitmap(mGL, MainContext, Tifo.mFriendRanking_img.get(x1));
						Button1.SetButton(img, ButtonType.TYPE_ONE_CLICK, 0, 100, 155+(x1*105), 0);
					} catch(Exception e) {
						Button1.SetButton(Point, ButtonType.TYPE_ONE_CLICK, 0, 80, 120+(x1*105), 12);
					}
				} else {
					Button1.SetButton(Point, ButtonType.TYPE_ONE_CLICK, 0, 80, 120+(x1*105), 12);
				}
			} else {
				Button1.SetButton(Point, ButtonType.TYPE_ONE_CLICK, 0, 80, 120+(x1*105), 12);
			}
			Button1.SetLinkTo(FriendRankingUI.UIList.get(i));
			RankingButton.add(Button1);

			///////////////// 메세지 전송 /////////////////
			ButtonObject Button2 = new ButtonObject();
			Button2.SetButton(Point, ButtonType.TYPE_ONE_CLICK, 0, 400, 125+(x1*105), 6);
			Button2.SetLinkTo(FriendRankingUI.UIList.get(i));
			RankingSendButton.add(Button2);

			x1++;
		}	
    	GameMode = 91;  // 
		
	}
	/**
	 * 게임스토리 
	 */
	public void LoadCartoon() {
		cartoon.LoadSprite(mGL, MainContext, String.format("cartoon_%02d.spr", CartoonNum));
	}
	
    public void LoadCartoonButton() {
    	cartoon_button.LoadSprite(mGL, MainContext, "cartoon_all.spr");
    	
		ButtonObject Button1 = new ButtonObject();
		Button1.SetButton(cartoon_button, ButtonType.TYPE_ONE_CLICK, 0, 700, 430, 0);
		SkipButton.add(Button1);
		
		ButtonObject Button2 = new ButtonObject();
		Button2.SetButton(cartoon_button, ButtonType.TYPE_ONE_CLICK, 0, 600, 430, 1);
		NextButton.add(Button2);

    }
	
	public void LoadFamilyMeet() {
		fy_meet_bk.LoadSprite(mGL, MainContext, "fy_meet.spr");
		fy_meet.LoadSprite(mGL, MainContext, String.format("fy_meet_%02d.spr", FamilyNum));
	}	
	public void LoadGameMain() {
		apply.LoadSprite(mGL, MainContext, "apply.spr");
		item.LoadSprite(mGL, MainContext, "item.spr");
		LoadFire();
		
		LawButton = null;
		LawButton = new ArrayList<ButtonObject>();
		
		ButtonObject button = new ButtonObject();
		button.SetButton( apply, ButtonType.TYPE_ONE_CLICK, 0, 530, 370,  1);
		LawButton.add( button );
		
		
		ApplyButton = null;
		ApplyButton = new ArrayList<ButtonObject>();
		
		ButtonObject button1 = new ButtonObject();
		button1.SetButton( apply, ButtonType.TYPE_ONE_CLICK, 0, 170, 370,  0);
		ApplyButton.add( button1 );
		
		
		LoginUI.LoadUI( mGL, MainContext, "login.ui" ); // UI 파일을 로드한다.
		LoginUI.AddGroup( 0, 0 );

		
	}
	
	public void LoadMapData() {
		key.LoadSprite(mGL, MainContext, "key.spr");
		
		map.LoadSprite(mGL, MainContext, "map.spr");
		MapButton = null;
		MapButton = new ArrayList<ButtonObject>();
		
		for (int i = 0; i < 4; i++ )
		{
			ButtonObject button = new ButtonObject();
			button.SetButton( map, ButtonType.TYPE_ONE_CLICK, 0, 50 + ((i % 8) * 180), 150 + ((i / 8) * 100), i );
			MapButton.add( button );
		}
		GameMode = 3;
		bGameOver = false;
		
	}
	/**
	 * stage button 생성
	 */
	public void LoadIntroData()
	{
		score_ovr.LoadSprite(mGL, MainContext, "score_ovr.spr");
		OverButton.SetButton(score_ovr, ButtonType.TYPE_ONE_CLICK, 0, 400, 250, 0);
		GameOverButton.SetButton(score_ovr, ButtonType.TYPE_ONE_CLICK, 0, 400, 250, 2);
		GameOverButton.SetLinkTo(OverButton);
		
		TimeOverButton.SetButton(score_ovr, ButtonType.TYPE_ONE_CLICK, 0, 400, 250, 3);
		TimeOverButton.SetLinkTo(OverButton);
		
		LoadStageButton();

	}
	
	public void LoadStageButton() {
		Button = null;
		Button = new ArrayList<ButtonObject>();
		int p = end - start;

		int x = start;
		for (int i = 0; i <= p; i++ )
		{
			ButtonObject button = new ButtonObject();
			ButtonObject button1 = new ButtonObject();
			if(start == 0 || start == 11) {
				button.SetButton( key, ButtonType.TYPE_ONE_CLICK, 0, 60 + ((i % 7) * 100), 150 + ((i / 7) * 100), StageData[x] == 0 ? 2 : 1 );
			} else {
				button.SetButton( key, ButtonType.TYPE_ONE_CLICK, 0, 100 + ((i % 8) * 130), 190 + ((i / 8) * 100), StageData[x] == 0 ? 2 : 1 );
			}
			if(x < 10 && StageData[x] == 1) {
				button.SetText(0, 23, 16, 0, 0, 0, 30, x+"", 40, 30);
				button.current = 0;
		
			} else if(x < 10 && StageData[x] == 0) {
				button.current = 1;
			}
			if(x > 9 && StageData[x] == 1) {
				button.SetText(0, 17, 16, 0, 0, 0, 30, x+"", 40, 30);
				button.current = 0;
			} else if(x > 9 && StageData[x] == 0) {
				button.current = 1;
			}
			Button.add( button );
			x++;
		}
	}
	public void LoadGameData()
	{
		bGameOver = false;
		Target = null;
		left_right = false;
		distance = 35.0f;
		Moving = false;
		bSpider = false;
		over = false;		
		FamilyNum = 1;
		
//		StageNum = 4;
		effect.LoadSprite(mGL, MainContext, "score.spr");
		bomb.LoadSprite(mGL, MainContext, "bomb02.spr");
		water_cha.LoadSprite(mGL, MainContext, "water_cha.spr");
		light.LoadSprite(mGL, MainContext, "laser03.spr");
		preci_bomb.LoadSprite(mGL, MainContext, "preci_bomb.spr");
		StartGameTimer = System.currentTimeMillis();

		
		stage = new Project();
		
		stage.LoadProject(mGL, MainContext, String.format("stage%02d.proj", StageNum));
//		stage.LoadProject(mGL, MainContext, "test.proj");

        Game.clear();
        ///// 티포 객체 
		for ( int i = 0; i < stage.MapData.get(0).size(); i++ )
		{
			if ( stage.MapData.get(0).get(i).type == 100)
			{
				Target = stage.MapData.get(0).get(i);
				Target.crash = 0;
				Target.attack = 0;
			}
		}
		gInfo.SetCrashScreen(1600, 960);
        gInfo.ScrollY = stage.MapScrollY - gInfo.ScreenY;
       
       
	}
	

	/*
	 * 보석을 드래그해서 이동해야 할 위치에 다른 보석이 있는지 체크하고 있으면 그 보석의 객체를 리턴한다.
	 */
	public GameObject GetBox( int x, int y )
	{
		for ( int i = 0; i < stage.MapData.get(0).size(); i++ )
		{
			if ( stage.MapData.get(0).get(i).type == 70 || (stage.MapData.get(0).get(i).type >= 85 && stage.MapData.get(0).get(i).type <= 88))
			{
				if ( stage.MapData.get(0).get(i).x / 60 == x && stage.MapData.get(0).get(i).y / 56 == y ) {
					return stage.MapData.get(0).get(i);
				}
			} 	
		}
		
		return null;		
	}
	
	public boolean checkPos(int x, int y)
	{
		for ( int i = 0; i < stage.MapData.get(0).size(); i++ )
		{
			if ( stage.MapData.get(0).get(i).type < 100)
			{
				if (stage.MapData.get(0).get(i).x / 60 == x && stage.MapData.get(0).get(i).y / 56 == y ) {
					System.out.println("check type = " + stage.MapData.get(0).get(i).type);
					return false;
				}
			} 
		}
		if((StageNum > 10 && StageNum < 21) ) return false;
		return true;			
	}
	
	/*
	 * 갤럭터가 위치하고 있는 현재의 상태가 무엇인지 첵크 하는 메소드 
	 */
	public GameObject GetNowPositionStatus( int x, int y )
	{
		for ( int i = 0; i < stage.MapData.get(0).size(); i++ )
		{
			if ( stage.MapData.get(0).get(i).type != 100)
			{
				if(stage.MapData.get(0).get(i).CheckPos(x, y)) {
					return stage.MapData.get(0).get(i);
				}
			}
		}
		
		for ( int i = 0; i < stage.MapData.get(3).size(); i++ )
		{
			if(stage.MapData.get(3).get(i).CheckPos(x, y)) {
				return stage.MapData.get(3).get(i);
			}
		}			
		return null;		
	}
	
	public GameObject GetNowPositionStatus2( int x, int y )
	{
		for ( int i = 0; i < stage.MapData.get(0).size(); i++ )
		{
			if ( stage.MapData.get(0).get(i).type != 100 )
			{
				if(stage.MapData.get(0).get(i).CheckPos(x, y)) {
					return stage.MapData.get(0).get(i);
				}
			}
		}
		
		return null;		
	}	
	/*
	 * 에너지를 먹었는지 확인 
	 */
	public GameObject GetEnergy( int x, int y )
	{
//		System.out.println("............. GetEnergy ");

		for ( int i = 0; i < stage.MapData.get(0).size(); i++ )
		{
			if ( stage.MapData.get(0).get(i).type >= 3 &&  stage.MapData.get(0).get(i).type <= 9)
			{
//				System.out.println(stage.MapData.get(0).get(i).x  + " .. " + stage.MapData.get(0).get(i).y);
//				System.out.println((int)stage.MapData.get(0).get(i).x / 46 + " .. " + x + " ... " + (int)stage.MapData.get(0).get(i).y / 50 + " .. " + y );
				
//				if(Math.abs(x - (int)stage.MapData.get(0).get(i).x / 60) <= 60 && Math.abs(y -(int)stage.MapData.get(0).get(i).y - 56) <= 56) 
		        if((int)stage.MapData.get(0).get(i).x / 60 == x && (int)stage.MapData.get(0).get(i).y / 56 == y && stage.MapData.get(0).get(i).move == Const.STOP)  // 플레이어와 충돌을 체크한다.
    			{
//					System.out.println("............. ok GetEnergy");
		        	stage.MapData.get(0).get(i).move = Const.READY;
					return stage.MapData.get(0).get(i);
				}
			}
		}	
		return null;		
	}
	
	public void PushButton( boolean flag )
	{
		/**
		 * UI용 터치 처리 전용 함수
		 */
		AlterUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		if(GameMode == 1) {
		    for ( int i = 0; i < SkipButton.size(); i++ ) SkipButton.get(i).CheckButton( gInfo, flag, TouchX, TouchY );
		    for ( int i = 0; i < NextButton.size(); i++ ) NextButton.get(i).CheckButton( gInfo, flag, TouchX, TouchY );
		} else if(GameMode == 2) {
			LoginUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
//		    for ( int i = 0; i < LawButton.size(); i++ ) LawButton.get(i).CheckButton( gInfo, flag, TouchX, TouchY );
//		    for ( int i = 0; i < ApplyButton.size(); i++ ) ApplyButton.get(i).CheckButton( gInfo, flag, TouchX, TouchY );
		} else if(GameMode == 3) {
		    for ( int i = 0; i < MapButton.size(); i++ ) MapButton.get(i).CheckButton( gInfo, flag, TouchX, TouchY );
		} else if(GameMode == 4) {
		    for ( int i = 0; i < Button.size(); i++ ) Button.get(i).CheckButton( gInfo, flag, TouchX, TouchY );
		} else if(GameMode == 84) {
			HelpUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		} else if(GameMode == 85) {
			DataChkUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		} else if(GameMode == 90) {
			NoticeUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		} else if(GameMode == 91) {
			FriendRankingUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		    for ( int i = 0; i < RankingSendButton.size(); i++ ) RankingSendButton.get(i).CheckButton( gInfo, flag, TouchX, TouchY );
		} else if(GameMode == 92) {
			SettingUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		} else if(GameMode == 93) {
			Friend_InVitUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		    for ( int i = 0; i < InVitSendButton.size(); i++ ) InVitSendButton.get(i).CheckButton( gInfo, flag, TouchX, TouchY );
		} else if(GameMode == 94) {
			TimeBuyUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		} else if(GameMode == 95) {
			TifoBuyUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		} else if(GameMode == 96) {
			ResultUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		} else if(GameMode == 99) {
			QuitUI.Touch( gInfo, (int)TouchX, (int)TouchY, flag );
		} else if(GameMode == 5) {
			OverButton.CheckButton( gInfo, flag, TouchX, TouchY );
			GameOverButton.CheckButton( gInfo, flag, TouchX, TouchY );
			TimeOverButton.CheckButton( gInfo, flag, TouchX, TouchY );
			if(over) return;
			if ( flag ) // 터치를 했거나 터치한 상태로 이동한 경우
			{
				if ( Target == null ) // Target이 아직 아무것도 가리키지 않는 상태이면
				{
					int cnt = 0;
					for ( int i = 0; i < stage.MapData.get(0).size(); i++ )
					{
						if ( stage.MapData.get(0).get(i).type == 100 && stage.MapData.get(0).get(i).move != Const.DEAD )
						{
							Target = stage.MapData.get(0).get(i);
							Target.crash = 0;
							Target.attack = 0;

							cnt++;
						}
					}
				}
//				OldX = TouchX;
//				OldY = TouchY;
			}
			else // 터치를 뗐을 경우
			{
				System.out.println("OldX = " + OldX + " ... OldY = " +  OldY + " TouchX = " + TouchX + " .. TouchY = " + TouchY + " ... slideYn = " + slideYn);
				left_right = false;
				slideYn = 0;
				if( Math.abs(OldX - TouchX) > 15 || Math.abs(OldY - TouchY) > 15 )  slideYn = 1;

				if ( Target != null && Moving == false && Target.angle == 0 && slideYn == 1) // 선택해서 이동중이던 보석이 있다면
				{
					// 터치한 좌표와 보석의 좌표를 각각 절대좌표로 변환해서 가로로 이동한 거리가 긴지, 세로로 이동한 거리가 긴지에 따라 방향을 결정한다.
					slideYn = 0;

					
//					if ( Math.abs(TouchX+gInfo.ScrollX-Target.x) > Math.abs(TouchY+gInfo.ScrollY-Target.y) ) // 가로로 이동한 경우
					if ( Math.abs(TouchX - OldX)  > Math.abs(TouchY-OldY) ) // 가로로 이동한 경우
					{
//						if ( TouchX+gInfo.ScrollX > Target.x ) // 터치 좌표가 보석 좌표보다 오른쪽이므로 오른쪽으로 이동
						if ( TouchX > OldX ) // 터치 좌표가 보석 좌표보다 오른쪽이므로 오른쪽으로 이동
						{
							GameObject temp = GetBox( (int)(Target.x + 60) / 60,  (int)Target.y / 56 ); // 보석의 오른쪽에 다른 보석이 있는지 체크한다.
							
							GameObject nowPostionStat = GetNowPositionStatus((int)Target.x+60, (int)Target.y); // 11 스테이즈에 바위이미지가 커서 
							
							boolean bfound = false;
							if(nowPostionStat != null) {
								if(nowPostionStat.type == 70 || nowPostionStat.type == 94) bfound = true;
								if(nowPostionStat.type >= 85 && nowPostionStat.type <= 88) bfound = true;
								if(nowPostionStat.type == 14 && (nowPostionStat.frame < 4)) bfound = true;
								if(temp != null) {
									if(temp.type == 70 && (nowPostionStat.type == 14 || nowPostionStat.type == 13)) {
										bfound = true;
									}
								}
							}
							
							if ( (temp == null && null == nowPostionStat) || bfound == false) // 다른 보석이 있으면
//							if (temp == null)  // 다른 보석이 있으면
							{
								Target.crash = 0;
								Target.attack = 0;
								Target.move = Const.RIGHT; // 보석의 move 값을 오른쪽으로 설정
								Target.ox = Target.x + 60; // 보석의 목적 X좌표를 현재 좌표 +80으로 설정한다.
								Target.power = 400;			
								Target.oy = Target.y;
								left_right = true;
								pre_status = Const.RIGHT;
								if(Tifo.effect_sound.equals("Y")) PlaySound( 0 );
							}
						}
//						else if ( TouchX+gInfo.ScrollX < Target.x ) // 터치 좌표가 보석 좌표보다 왼쪽이므로 왼쪽으로 이동
						else if ( TouchX < OldX ) // 터치 좌표가 보석 좌표보다 왼쪽이므로 왼쪽으로 이동
						{
							GameObject temp = GetBox(  (int)(Target.x - 60) / 60,  (int)Target.y / 56); // 보석의 왼쪽에 다른 보석이 있는지 체크한다.
							
							GameObject nowPostionStat = GetNowPositionStatus((int)Target.x-60, (int)Target.y); // 11 스테이즈에 바위이미지가 커서 
							
							boolean bfound = false;
							if(nowPostionStat != null) {
								if(nowPostionStat.type == 70 || nowPostionStat.type == 94) bfound = true;
								if(nowPostionStat.type >= 85 && nowPostionStat.type <= 88) bfound = true;
								if(nowPostionStat.type == 14 && (nowPostionStat.frame < 4)) bfound = true;
								if(temp != null) {
									if(temp.type == 70 && (nowPostionStat.type == 14 || nowPostionStat.type == 13)) {
										bfound = true;
									}
								}
							}
							
							if ( (temp == null && null == nowPostionStat) || bfound == false) // 다른 보석이 있으면
//							if (temp == null)  // 다른 보석이 있으면
							{
								Target.crash = 0;
								Target.attack = 0;
								Target.move = Const.LEFT; // 보석의 move 값을 왼쪽으로 설정
								Target.ox = Target.x - 60; // 보석의 목적 X좌표를 현재 좌표 -80으로 설정한다.
								Target.power = 400;			
								Target.oy = Target.y;
								left_right = true;
								pre_status = Const.LEFT;
								if(Tifo.effect_sound.equals("Y")) PlaySound( 0 );
							}
						}
					}
					else // 세로로 이동한 경우
					{
						System.out.println("TouchY = " + TouchY + " Target.y = " + Target.y);
//						if ( TouchY+gInfo.ScrollY > Target.y ) // 터치 좌표가 보석 좌표보다 아래쪽이므로 아래으로 이동
						if ( TouchY > OldY ) // 터치 좌표가 보석 좌표보다 아래쪽이므로 아래으로 이동
						{
							GameObject temp = GetBox(  (int)Target.x / 60,  (int)(Target.y + 56) / 56 ); // 보석의 아래쪽에 다른 보석이 있는지 체크한다.
							GameObject nowPostionStat = GetNowPositionStatus((int)Target.x, (int)Target.y+ 56); // 11 스테이즈에 바위이미지가 커서 
							
							boolean bfound = false;
							if(nowPostionStat != null) {
								if(nowPostionStat.type == 70 || nowPostionStat.type == 94) bfound = true;
								if(nowPostionStat.type >= 85 && nowPostionStat.type <= 88) bfound = true;
								if(nowPostionStat.type == 14 && (nowPostionStat.frame < 4)) bfound = true;
								if(temp != null) {
									if(temp.type == 70 && (nowPostionStat.type == 14 || nowPostionStat.type == 13)) {
										bfound = true;
									}
								}
							}
							
							if ( (temp == null && null == nowPostionStat) || bfound == false) // 다른 보석이 있으면
//							if (temp == null)  // 다른 보석이 있으면
							{
								System.out.println("----------------------------down");
								Target.crash = 0;
								Target.attack = 0;
								Target.move = Const.DOWN; // 보석의 move 값을 아래쪽으로 설정
								Target.oy = Target.y + 56; // 보석의 목적 Y좌표를 현재 좌표 +80으로 설정한다.
								
								pre_status = Const.DOWN;
								if(Tifo.effect_sound.equals("Y")) PlaySound( 0 );
							}
							
						}
//						else if ( TouchY+gInfo.ScrollY  < Target.y ) // 터치 좌표가 보석 좌표보다 아래쪽이므로 아래으로 이동
						else if ( TouchY < OldY ) // 터치 좌표가 보석 좌표보다 아래쪽이므로 아래으로 이동
						{
							GameObject temp = GetBox(  (int)Target.x / 60,  (int)(Target.y - 56) / 56 ); // 보석의 위쪽에 다른 보석이 있는지 체크한다.
							GameObject nowPostionStat = GetNowPositionStatus((int)Target.x, (int)Target.y- 56); // 11 스테이즈에 바위이미지가 커서 
							boolean bfound = false;
							if(nowPostionStat != null) {
								if(nowPostionStat.type == 70 || nowPostionStat.type == 94) bfound = true;
								if(nowPostionStat.type >= 85 && nowPostionStat.type <= 88) bfound = true;
								if(nowPostionStat.type == 14 && (nowPostionStat.frame < 4)) bfound = true;
								if(temp != null) {
									if(temp.type == 70 && (nowPostionStat.type == 14 || nowPostionStat.type == 13)) {
										bfound = true;
									}
								}
							}
							
							if((temp == null && null == nowPostionStat) || bfound == false) // 다른 보석이 있으면
//							if (temp == null)  // 다른 보석이 있으면
							{
								System.out.println("------------------------------up " );
								Target.crash = 0;
								Target.attack = 0;
								Target.move = Const.UP; // 보석의 move 값을 위쪽으로 설정
								Target.oy = Target.y - 56; // 보석의 목적 Y좌표를 현재 좌표 +80으로 설정한다.
								
								Target.power = 500;			
								pre_status = Const.UP;
								if(Tifo.effect_sound.equals("Y")) PlaySound( 0 );
							}
						}
					}
				}

			}
		}
	}
	
    /*
     * 파티클 이펙트를 count의 개수만큼 생성한다.
     */
    private void MakeEffect( float x, float y, int count, boolean flag )
    {
		for ( int i = 0; i < count; i++ )
		{
			GameObject game = new GameObject();
			game.SetObject( effect, 0, 0, x, y, 6, 0 );
			game.power = 1000 + (MyRand.nextInt(10) * 30);
			game.direct = MyRand.nextInt(360);
			game.zx = 10;
			game.zy = 10;
			game.scroll = flag;
			game.dead = false;
			game.effect = 1;
			Game.add( game );
		}
    }

    /**
     * 폭주 
     * @param x
     * @param y
     * @param count
     * @param flag
     */
    private void MakeFire( float x, float y, int count, boolean flag, int frame )
    {
		for ( int i = 0; i < count; i++ )
		{
			GameObject game = new GameObject();
			game.SetObject( fire, 96, 0, x, y, 0, frame );
			game.power = 1000 + (MyRand.nextInt(10) * 30);
			game.direct = MyRand.nextInt(360);
			game.zx = 10;
			game.zy = 10;
			game.scroll = flag;
			game.dead = false;
			game.effect = 1;
			Game.add( game );
		}
    }
   
    private void MakeFlash( float x, float y, boolean flag )
    {
		GameObject game = new GameObject();
		game.SetObject(score_ovr, 0, 0, x, y, 4, 0 );
//		game.power = 1000 + (MyRand.nextInt(10) * 30);
//		game.direct = MyRand.nextInt(360);
		game.zx = 10;
		game.zy = 10;
		game.scroll = flag;
		game.dead = false;
		game.effect = 1;
		Game.add( game );
    }   
    /*
     * 대포 
     */
    private void MakeBomb( float x, float y, int type, boolean flag, int motion, int kind, int frame)
    {
		GameObject game = new GameObject();
		
		if(type == 100 && kind == 0) {
			game.SetObject( water_cha, 0, 0, x, y, 1, 0 );
		} else if(type == 89) {
			game.SetObject( light, 0, 0, x, y, motion, 0 );
		} else if(type == 94) {
			game.SetObject( preci_bomb, 0, 0, x, y, motion, 0 );
		} else {
			game.SetObject( bomb, 0, 0, x, y, motion, 0 );
		}
		game.zx = 10;
		game.zy = 10;
		game.scroll = flag;
		game.dead = false;
//		game.effect = 1;
		game.type = type;
		game.motion = motion;
		game.attack = kind;
		game.crash =  frame;
		if((StageNum == 11 ||  StageNum == 12 ||  StageNum == 13) && type == 89) {
			game.y = game.y - 60;
			game.SetZoom(gInfo, 1.0f, 0.60f );
		} else if(type == 100) {
			game.SetZoom(gInfo, 0.75f, 0.6f );
		} else if((StageNum == 14 || StageNum == 24 || StageNum == 25) && type == 89) {
			if(motion == 7) {
				game.y = game.y - 60;
				game.SetZoom(gInfo, 1.0f, 0.60f );
			} else {
				game.x = game.x - 60;
				game.SetZoom(gInfo, 0.58f, 1.0f );
			}
		} else if(StageNum == 16 && type == 89) {
			if(motion == 7) {
				game.y = game.y - 65;
				game.SetZoom(gInfo, 1.0f, 0.57f );
			}
		} else if((StageNum == 17 || StageNum == 22) && type == 89) {
			game.x = game.x - 50;
			game.SetZoom(gInfo, 0.75f, 1.0f );
		} else if(StageNum == 18 && type == 89) {
			game.x = game.x - 60;
			game.SetZoom(gInfo, 0.58f, 1.0f );
		} else if(StageNum == 24 && type == 89) {
			game.SetZoom(gInfo, 1.0f, 0.75f );
		}

		Game.add( game );
    } 
    
    
    /**
     * 스테이즈별로 통나무의 빠르기와 이동방향을 정리 
     * @param game
     */
    private void setTreeMoving(GameObject game) {
		if(StageNum < 2) {
			game.mx1 = 1;
			game.x += game.mx1;
		} else if(StageNum == 2) {
			if(game.type == 30) { 
				game.mx1 = 1;
				game.x += game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 33) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 34) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 35) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 36) { 
				game.mx1 = 3;
				game.x += game.mx1;
			}
		}  else if(StageNum == 3) {
			if(game.type == 30) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 33) { 
				game.mx1 = 4;
				game.x -= game.mx1;
			}
		}  else if(StageNum == 4) {
			if(game.type == 30) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 1;
				game.x += game.mx1;
			} else if(game.type == 33) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 34) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 35) { 
				game.mx1 = 4;
				game.x += game.mx1;
			}
		}  else if(StageNum == 5) {
			if(game.type == 30) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 33) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 34) { 
				game.mx1 = 4;
				game.x += game.mx1;
			} else if(game.type == 35) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 61) { 
				game.mx1 = 1;
				game.x += game.mx1;
			}
		}  else if(StageNum == 6) {
			if(game.type == 30) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 33) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 34) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 35) { 
				game.mx1 = 4;
				game.x += game.mx1;
			} else if(game.type == 61) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			}
		}  else if(StageNum == 7) {
			if(game.type == 30) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 61) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 33) { 
				game.mx1 = 4;
				game.x += game.mx1;
			}
		}  else if(StageNum == 8) {
			if(game.type == 81) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 82) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 64) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 63) { 
				game.mx1 = 1;
				game.x += game.mx1;
			} else if(game.type == 30) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 61) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 3;
				game.x += game.mx1;
			}
		}  else if(StageNum == 9) {
			if(game.type == 81) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 82) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 30) { 
				game.mx1 = 1;
				game.x += game.mx1;
			} else if(game.type == 61) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 41) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 42) { 
				game.mx1 = 4;
				game.x -= game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 33) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 43) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			}
		}  else if(StageNum == 10) {
			if(game.type == 30) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 64) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 63) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 61) { 
				game.mx1 = 1;				
				game.x += game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 41) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 42) { 
				game.mx1 = 3;
				game.x += game.mx1;
			}
		}  else if(StageNum == 11) {
			if(game.type == 83) { 
				game.my1 = 2;
				game.y += game.my1;
			}
		}  else if(StageNum == 12) {
			if(game.type == 83) { 
				game.my1 = 2;
				game.y += game.my1;
			}
			
		}  else if(StageNum == 14) {
			if(game.type == 83) { 
				game.my1 = 2;
				game.y += game.my1;
			} else if(game.type == 15) { 
				if(game.x >= 1200) {
					game.delay = 2;
				} else if(game.x <= 660) {
					game.delay = 1;		
				}
				if(game.delay == 1) {
					game.mx1 = 2;
					game.x += game.mx1;
				} else {
					game.mx1 = 2;
					game.x -= game.mx1;
				}
			} else if(game.type == 16) { 
				if(game.x >= 1200) {
					game.delay = 2;
				} else if(game.x <= 660) {
					game.delay = 1;		
				}
				if(game.delay == 1) {
					game.mx1 = 3;
					game.x += game.mx1;
				} else {
					game.mx1 = 3;
					game.x -= game.mx1;
				}
			} else if(game.type == 17) { 
				if(game.x >= 1200) {
					game.delay = 2;
				} else if(game.x <= 660) {
					game.delay = 1;		
				}
				if(game.delay == 1) {
					game.mx1 = 1;
					game.x += game.mx1;
				} else {
					game.mx1 = 1;
					game.x -= game.mx1;
				}
			}
		}  else if(StageNum == 15) {
			if(game.type == 15) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 16) { 
				game.mx1 = 1;
				game.x += game.mx1;
			} else if(game.type == 17) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			}
		}  else if(StageNum == 16) {
			if(game.type == 15) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 16) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 17) { 
				game.mx1 = 1;
				game.x += game.mx1;
			} else if(game.type == 18) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 1) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 3) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 94 && game.motion == 5) { 
				game.my1 = 3;
				game.y -= game.my1;
			} else if(game.type == 94 && game.motion == 7) { 
				game.my1 = 3;
				game.y += game.my1;
			}
		}  else if(StageNum == 17) {
			if(game.type == 15) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 16) { 
				game.mx1 = 1;
				game.x += game.mx1;
			} else if(game.type == 17) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 18) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 3 && game.y == 3132) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 3 && game.y == 3079) { 
				game.mx1 = 1;
				game.x += game.mx1;
			} else if(game.type == 3 && game.y == 3019) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 1) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 3) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 94 && game.motion == 5) { 
				game.my1 = 3;
				game.y -= game.my1;
			} else if(game.type == 94 && game.motion == 7) { 
				game.my1 = 3;
				game.y += game.my1;
			}
		}  else if(StageNum == 18) {
			if(game.type == 15) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 16) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 17) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 18) { 
				game.mx1 = 1;
				game.x += game.mx1;
			} else if(game.type == 94 && game.motion == 1) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 3) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 94 && game.motion == 5) { 
				game.my1 = 3;
				game.y -= game.my1;
			} else if(game.type == 94 && game.motion == 7) { 
				game.my1 = 3;
				game.y += game.my1;
			}
		}  else if(StageNum == 19) {
			if(game.type == 94 && game.motion == 1) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 3) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 94 && game.motion == 5) { 
				game.my1 = 3;
				game.y -= game.my1;
			} else if(game.type == 94 && game.motion == 7) { 
				game.my1 = 3;
				game.y += game.my1;
			}
		}  else if(StageNum == 20) {
			if(game.type == 94 && game.motion == 1) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 3) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 94 && game.motion == 5) { 
				game.my1 = 3;
				game.y -= game.my1;
			} else if(game.type == 94 && game.motion == 7) { 
				game.my1 = 3;
				game.y += game.my1;
			} else if(game.type == 15) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 16) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 17) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 18) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 19) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			}
		}  else if(StageNum == 21) {
			if(game.type == 83) { 
				game.my1 = 2;
				game.y += game.my1;
			} else if(game.type == 84) { 
				game.my1 = 2;
				game.y -= game.my1;
			}
		}  else if(StageNum == 22 || StageNum == 23 || StageNum == 24 || StageNum == 25) {
			if(game.type == 94 && game.motion == 1) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 3) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 94 && game.motion == 5) { 
				game.my1 = 3;
				game.y -= game.my1;
			} else if(game.type == 94 && game.motion == 7) { 
				game.my1 = 3;
				game.y += game.my1;
			}
		}  else if(StageNum == 26) {
			if(game.type == 30) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 33) { 
				game.mx1 = 4;
				game.x -= game.mx1;
			}
		}  else if(StageNum == 27) {
			if(game.type == 30) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 61) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 33) { 
				game.mx1 = 4;
				game.x += game.mx1;
			}
		}  else if(StageNum == 28) {
			if(game.type == 30) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 33) { 
				game.mx1 = 4;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 1) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 3) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 94 && game.motion == 5) { 
				game.my1 = 3;
				game.y -= game.my1;
			} else if(game.type == 94 && game.motion == 7) { 
				game.my1 = 3;
				game.y += game.my1;
			}
		}  else if(StageNum == 29) {
			if(game.type == 94 && game.motion == 1) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 94 && game.motion == 3) { 
				game.mx1 = 3;
				game.x += game.mx1;
			} else if(game.type == 94 && game.motion == 5) { 
				game.my1 = 3;
				game.y -= game.my1;
			} else if(game.type == 94 && game.motion == 7) { 
				game.my1 = 3;
				game.y += game.my1;
			}
		}  else if(StageNum == 30) {
			if(game.type == 81) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 82) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 64) { 
				game.mx1 = 1;
				game.x -= game.mx1;
			} else if(game.type == 63) { 
				game.mx1 = 1;
				game.x += game.mx1;
			} else if(game.type == 30) { 
				game.mx1 = 2;
				game.x -= game.mx1;
			} else if(game.type == 31) { 
				game.mx1 = 3;
				game.x -= game.mx1;
			} else if(game.type == 61) { 
				game.mx1 = 2;
				game.x += game.mx1;
			} else if(game.type == 32) { 
				game.mx1 = 3;
				game.x += game.mx1;
			}
		}
    }
    
    private void setTifoWithTreeMoving(GameObject game, GameObject tree) {
		if(StageNum < 2) {
			game.x += tree.mx1;
		} else if(StageNum == 2) {
			if(tree.type == 30) { 
				game.x += tree.mx1;
			} else if(tree.type == 31) { 
				game.x -= tree.mx1;
			} else if(tree.type == 32) { 
				game.x += tree.mx1;
			} else if(tree.type == 33) { 
				game.x -= tree.mx1;
			} else if(tree.type == 34) { 
				game.x += tree.mx1;
			} else if(tree.type == 35) { 
				game.x -= tree.mx1;
			} else if(tree.type == 36) { 
				game.x += tree.mx1;
			}
		}  else if(StageNum == 3) {
			if(tree.type == 30) { 
				game.x += tree.mx1;
			} else if(tree.type == 31) { 
				game.x -= tree.mx1;
			} else if(tree.type == 32) { 
				game.x -= tree.mx1;
			} else if(tree.type == 33) { 
				game.x -= tree.mx1;
			}
		}  else if(StageNum == 4) {
			if(tree.type == 30) { 
				game.x += tree.mx1;
			} else if(tree.type == 31) { 
				game.x -= tree.mx1;
			} else if(tree.type == 32) { 
				game.x += tree.mx1;
			} else if(tree.type == 33) { 
				game.x -= tree.mx1;
			} else if(tree.type == 34) { 
				game.x += tree.mx1;
			} else if(tree.type == 35) { 
				game.x += tree.mx1;
			}
		}  else if(StageNum == 5) {
			if(tree.type == 30) { 
				game.x -= tree.mx1;
			} else if(tree.type == 31) { 
				game.x -= tree.mx1;
			} else if(tree.type == 32) { 
				game.x += tree.mx1;
			} else if(tree.type == 33) { 
				game.x += tree.mx1;
			} else if(tree.type == 34) { 
				game.x += tree.mx1;
			} else if(tree.type == 35) { 
				game.x -= tree.mx1;
			} else if(tree.type == 61) { 
				game.x += tree.mx1;
			}
		}  else if(StageNum == 6) {
			if(tree.type == 30) { 
				game.x += tree.mx1;
			} else if(tree.type == 31) { 
				game.x -= tree.mx1;
			} else if(tree.type == 32) { 
				game.x -= tree.mx1;
			} else if(tree.type == 33) { 
				game.x += tree.mx1;
			} else if(tree.type == 34) { 
				game.x -= tree.mx1;
			} else if(tree.type == 35) { 
				game.x += tree.mx1;
			} else if(tree.type == 61) { 
				game.x -= tree.mx1;
			}
		}  else if(StageNum == 7) {
			if(tree.type == 30) { 
				game.x += tree.mx1;
			} else if(tree.type == 31) { 
				game.x += tree.mx1;
			} else if(tree.type == 32) { 
				game.x -= tree.mx1;
			} else if(tree.type == 61) { 
				game.x -= tree.mx1;
			} else if(tree.type == 33) { 
				game.x += tree.mx1;
			}
		}  else if(StageNum == 8) {
			if(tree.type == 81) { 
				game.x -= tree.mx1;
			} else if(tree.type == 82) { 
				game.x += tree.mx1;
			} else if(tree.type == 30) { 
				game.x -= tree.mx1;
			} else if(tree.type == 31) { 
				game.x -= tree.mx1;
			} else if(tree.type == 61) { 
				game.x += tree.mx1;
			} else if(tree.type == 32) { 
				game.x += tree.mx1;
			}
		}  else if(StageNum == 9) {
			if(tree.type == 30) { 
				game.x += tree.mx1;
			} else if(tree.type == 61) { 
				game.x -= tree.mx1;
			} else if(tree.type == 41) { 
				game.x -= tree.mx1;
			} else if(tree.type == 42) { 
				game.x -= tree.mx1;
			} else if(tree.type == 31) { 
				game.x += tree.mx1;
			} else if(tree.type == 32) { 
				game.x -= tree.mx1;
			} else if(tree.type == 33) { 
				game.x += tree.mx1;
			} else if(tree.type == 43) { 
				game.x -= tree.mx1;
			}
		}  else if(StageNum == 10) {
			if(tree.type == 30) { 
				game.x += tree.mx1;
			} else if(tree.type == 64) { 
				game.x -= tree.mx1;
			} else if(tree.type == 63) { 
				game.x += tree.mx1;
			} else if(tree.type == 61) { 
				game.x += tree.mx1;
			} else if(tree.type == 31) { 
				game.x += tree.mx1;
			} else if(tree.type == 41) { 
				game.x += tree.mx1;
			} else if(tree.type == 42) { 
				game.x += tree.mx1;
			}
		}  else if(StageNum == 14) {
			if(tree.type == 83) { 
				game.y += tree.my1;
			} else if(tree.type == 15) { 
				if(tree.delay == 1) {
					game.x += tree.mx1;
				} else {
					game.x -= tree.mx1;
				}
			} else if(tree.type == 16) { 
				if(tree.delay == 1) {
					game.x += tree.mx1;
				} else {
					game.x -= tree.mx1;
				}
			} else if(tree.type == 17) { 
				if(tree.delay == 1) {
					game.x += tree.mx1;
				} else {
					game.x -= tree.mx1;
				}
			}
		}  else if(StageNum == 15) {
			if(tree.type == 15) { 
				game.x -= tree.mx1;
			} else if(tree.type == 16) { 
				game.x += tree.mx1;
			} else if(tree.type == 17) { 
				game.x -= tree.mx1;
			}
		}  else if(StageNum == 16) {
			if(tree.type == 15) { 
				game.x -= tree.mx1;
			} else if(tree.type == 16) { 
				game.x += tree.mx1;
			} else if(tree.type == 17) { 
				game.x += tree.mx1;
			} else if(tree.type == 18) { 
				game.x -= tree.mx1;
			}
		}  else if(StageNum == 17) {
			if(tree.type == 15) { 
				game.x -= tree.mx1;
			} else if(tree.type == 16) { 
				game.x += tree.mx1;
			} else if(tree.type == 17) { 
				game.x -= tree.mx1;
			} else if(tree.type == 18) { 
				game.x += tree.mx1;
			}
		}  else if(StageNum == 18) {
			if(tree.type == 15) { 
				game.x -= tree.mx1;
			} else if(tree.type == 16) { 
				game.x += tree.mx1;
			} else if(tree.type == 17) { 
				game.x -= tree.mx1;
			} else if(tree.type == 18) { 
				game.x += tree.mx1;
			}
		}  else if(StageNum == 20) {
			if(tree.type == 15) { 
				game.x += tree.mx1;
			} else if(tree.type == 16) { 
				game.x -= tree.mx1;
			} else if(tree.type == 17) { 
				game.x += tree.mx1;
			} else if(tree.type == 18) { 
				game.x -= tree.mx1;
			} else if(tree.type == 19) { 
				game.x -= tree.mx1;
			}		
		}  else if(StageNum == 26) {
			if(tree.type == 30) { 
				game.x += tree.mx1;
			} else if(tree.type == 31) { 
				game.x -= tree.mx1;
			} else if(tree.type == 32) { 
				game.x -= tree.mx1;
			} else if(tree.type == 33) { 
				game.x -= tree.mx1;
			}
		}  else if(StageNum == 27) {
			if(tree.type == 30) { 
				game.x += tree.mx1;
			} else if(tree.type == 31) { 
				game.x += tree.mx1;
			} else if(tree.type == 32) { 
				game.x -= tree.mx1;
			} else if(tree.type == 61) { 
				game.x -= tree.mx1;
			} else if(tree.type == 33) { 
				game.x += tree.mx1;
			}
		}  else if(StageNum == 28) {
			if(tree.type == 30) { 
				game.x += tree.mx1;
			} else if(tree.type == 31) { 
				game.x -= tree.mx1;
			} else if(tree.type == 32) { 
				game.x -= tree.mx1;
			} else if(tree.type == 33) { 
				game.x -= tree.mx1;
			}
		}  else if(StageNum == 30) {
			if(tree.type == 81) { 
				game.x -= tree.mx1;
			} else if(tree.type == 82) { 
				game.x += tree.mx1;
			} else if(tree.type == 30) { 
				game.x -= tree.mx1;
			} else if(tree.type == 31) { 
				game.x -= tree.mx1;
			} else if(tree.type == 61) { 
				game.x += tree.mx1;
			} else if(tree.type == 32) { 
				game.x += tree.mx1;
			}
		}   	
    }
    
    public void UpdatePlayerPostion(GameObject game, int type) {
    	if(Target != null) {
    		if(type == 10 || (type >= 15 && type <= 19)) {
    			float gameEndx = 0;
    			float gameEndy = 0;
    			if(Target.attack == 0) {
    				gameEndx =  game.x + 24;
        			gameEndy =  game.y + 30;
        			Target.attack = 1;
    			}
    			if(gameEndx > Target.x) {
    				Target.x += 10;
    			}
    			if(gameEndy > Target.y) {
    				Target.y += 10;
    			}
    		} else {
        		if(Target.attack == 0) {
        			Target.attack = 1; 
                	float gameEndX = game.x + game.GetXsize();
                	float playEndX = Target.x + Target.GetXsize();
                	if(gameEndX < playEndX + 35) {
                		Target.x = Target.x - 10;
//        				Target.crash = 0;
//        				Target.move = Const.LEFT; // 보석의 move 값을 왼쪽으로 설정
//        				Target.ox = Target.x - 30; // 보석의 목적 X좌표를 현재 좌표 -80으로 설정한다.
//        				Target.power = 400;			
//        				Target.oy = Target.y;
                	} else if(Target.x < game.x+ 35) {
                		Target.x = Target.x  + 10;   	
//        				Target.crash = 0;
//        				Target.move = Const.RIGHT; // 보석의 move 값을 오른쪽으로 설정
//        				Target.ox = Target.x + 60; // 보석의 목적 X좌표를 현재 좌표 +80으로 설정한다.
//        				Target.power = 400;			
//        				Target.oy = Target.y;   
        			 }    			
        		}    			
    		}

    	}
    }
    
    public void updateEffect(ArrayList<GameObject> game) {
		for (int i = 0; i < game.size(); i++ )
		{
			if ( game.get(i).type == 0) // 불꽃 이펙트
			{
				// direct 값이 가진 각도로 power / 100 만큼 이동한다.
				game.get(i).MovebyAngle( gInfo, game.get(i).direct, game.get(i).power / 100 );
				game.get(i).Zoom( gInfo, -0.02f, -0.02f ); // -0.02f 만큼씩 축소시킨다.
				
				game.get(i).power -= 100; // 파워를 -100씩 감소시킨다.
				if ( game.get(i).power < 100 ) game.get(i).power = 100; // 파워가 100 이하가 되지 않도록 제한한다.
				
				if ( game.get(i).scalex <= 0.2f ) game.get(i).dead = true; // 스케일이 0.2f 이하로 축소되면 삭제한다.
			} else if(game.get(i).type >= 81 && game.get(i).type <= 84) {
				setTreeMoving(game.get(i));
				game.get(i).AddFrame(0.02f);
				if(game.get(i).frame >= 4) {
					game.get(i).frame = 0;
				}
				if(Target != null) {
					if(game.get(i).CheckPos((int)Target.x, (int)Target.y)) {
						MakeEffect( Target.x, Target.y, 20, true ); // 불꽃 이펙트 생성
						if(Tifo.effect_sound.equals("Y")) PlaySound( 2 );
						Target.move = Const.DEAD;
						Target = null;
					}
				}
				if((game.get(i).x < 0 || game.get(i).x > 800) && StageNum < 14) game.get(i).dead = true;
				if(game.get(i).y < 0 || game.get(i).y > 12500) game.get(i).dead = true;
		    } else if(game.get(i).type == 89) {  // 레이저 대포 
		    	game.get(i).AddFrame(0.2f);

				if(game.get(i).frame >= 3) {
					game.get(i).dead = true;
				}
				if(Target != null) {
					if(game.get(i).CheckPos((int)Target.x, (int)Target.y)) {
						MakeFlash( Target.x, Target.y, true ); // 불꽃 이펙트 생성
						if(Tifo.effect_sound.equals("Y")) PlaySound( 5 );
						Target.move = Const.DEAD;
						Target = null;
					}
				}
			} else if(game.get(i).type == 94) {
				setTreeMoving(game.get(i));
				game.get(i).AddFrame(0.2f);
				if(game.get(i).frame >= 10) {
					game.get(i).frame = 2;
				}
				if(Target != null) {
					if(game.get(i).CheckPos((int)Target.x, (int)Target.y)) {
						MakeEffect( Target.x, Target.y, 20, true ); // 불꽃 이펙트 생성
						if(Tifo.effect_sound.equals("Y")) PlaySound( 2 );
						Target.move = Const.DEAD;
						Target = null;
					}
				}
				if((game.get(i).x < 0 || game.get(i).x > 800) && (StageNum > 15 && StageNum < 21)) game.get(i).dead = true;
				if((game.get(i).y < 0 || game.get(i).y > 12500) && StageNum < 21) game.get(i).dead = true;
			} else if ( game.get(i).type == 96)  // 폭죽 
				{
					game.get(i).AddFrame(0.2f);
					if(game.get(i).frame >= 2) {
						game.get(i).frame = 0;
					}

					// direct 값이 가진 각도로 power / 100 만큼 이동한다.
					game.get(i).MovebyAngle( gInfo, game.get(i).direct, game.get(i).power / 100 );
					game.get(i).Zoom( gInfo, -0.02f, -0.02f ); // -0.02f 만큼씩 축소시킨다.
					
					game.get(i).power -= 100; // 파워를 -100씩 감소시킨다.
					if ( game.get(i).power < 100 ) game.get(i).power = 100; // 파워가 100 이하가 되지 않도록 제한한다.
					
					if ( game.get(i).scalex <= 0.2f ) game.get(i).dead = true; // 스케일이 0.2f 이하로 축소되면 삭제한다.
			} else if(game.get(i).type == 100) {
				if(game.get(i).attack == 0) { // 바다 빠진 경우
					if(Target != null) Target.show = false;
					game.get(i).AddFrame(0.3f);
					if(game.get(i).frame >= game.get(i).crash) {
		    			over = true;
//						pointNum = pre_pointNum;
//						game.get(i).dead = true;
//						if(Tifo.effect_sound.equals("Y")) PlaySound( 3 );
//						
//						bGameOver =  true;
//						tifoCount--;
					}	
				}
			}
			if ( game.get(i).dead ) game.remove( i-- ); // 죽은 오브젝트를 어레이 리스트에서 삭제한다.
		}
   	
    }
 	public void UpdateGame()
	{
//		for ( int i = 0; i < stage.MapData.get(2).size(); i++ )
//		{
//			stage.MapData.get(2).get(i).scroll = false;
//			
//			{
//
//				stage.MapData.get(2).get(i).y += 1;
//
//				stage.MapData.get(2).get(i).PutSprite( gInfo );
//				
//				if ( stage.MapData.get(2).get(i).y1 >= gInfo.ScreenY ) stage.MapData.get(2).get(i).y -= 950;
//			}
//		}
		
//		for ( int i = 0; i < stage.MapData.get(1).size(); i++ )
//		{
//			stage.MapData.get(1).get(i).scroll = false;
//			
//			{
//				stage.MapData.get(1).get(i).y += 2;
//				stage.MapData.get(1).get(i).PutSprite( gInfo );
//				
//				if ( stage.MapData.get(1).get(i).y1 >= gInfo.ScreenY ) stage.MapData.get(1).get(i).y -= 1024;
//			}
//		}
 		updateEffect(Game);
//		if(gInfo.ScrollY >= stage.MapScrollY - gInfo.ScreenY) gInfo.ScrollY = stage.MapScrollY - gInfo.ScreenY;  // 아래 땅이 고정 되게 하기 위해서
//		if(gInfo.ScrollY <= 0) gInfo.ScrollY = 1;  // 윗의  땅이 고정 되게 하기 위해서
//		if(gInfo.ScrollX <= 0 && StageNum > 10) gInfo.ScrollX = 0;  // 아래 땅이 고정 되게 하기 위해서
//		if(StageNum >= 11 && gInfo.ScrollX >= stage.MapScrollX - gInfo.ScreenX) gInfo.ScrollX = stage.MapScrollX - gInfo.ScreenX; 
		
		for ( int i = 0; i < stage.MapData.get(0).size(); i++ )
		{
//			stage.MapData.get(0).get(i).show = true;
			if(stage.MapData.get(0).get(i).move == Const.DEAD) {
				if(stage.MapData.get(0).get(i).type == 100) {   // 티포가 죽으면 게임을 다시 시작한다 
					if(stage.MapData.get(0).get(i).current == 1) {  // 바다에 빠지는 경우 
						int motion = 0;
						if(stage.MapData.get(0).get(i).motion == 0) {
							motion = stage.MapData.get(0).get(i).motion;
						} else if(stage.MapData.get(0).get(i).motion == 1) {
							motion = 3;
						} else if(stage.MapData.get(0).get(i).motion == 2) {
							motion = 1;
						} else if(stage.MapData.get(0).get(i).motion == 3) {
							motion = 2;
						}
						MakeBomb( stage.MapData.get(0).get(i).x, stage.MapData.get(0).get(i).y, stage.MapData.get(0).get(i).type, true, motion, 0, 5); 
						stage.MapData.get(0).remove( i-- );
					} else {
						stage.MapData.get(0).get(i).angle += 20; // 오른쪽으로 20도씩 회전
						stage.MapData.get(0).get(i).Zoom( gInfo, -0.05f, -0.05f ); // -0.05%씩 보석이 축소되면서 사라지게 한다.
						if(stage.MapData.get(0).get(i).crash == 0 ) {
							stage.MapData.get(0).get(i).mx1 = stage.MapData.get(0).get(i).GetYsize();
							stage.MapData.get(0).get(i).crash = 1;
						}
						stage.MapData.get(0).get(i).mx1 -= 0.05f;
						if(stage.MapData.get(0).get(i).angle >= 360) {
//							bGameOver = true;					
//							pointNum = pre_pointNum;
//							if(Tifo.effect_sound.equals("Y")) PlaySound( 3 );
//							tifoCount--;
							over = true;
						}
					}
				} else {
					stage.MapData.get(0).get(i).angle += 20; // 오른쪽으로 20도씩 회전
					stage.MapData.get(0).get(i).Zoom( gInfo, -0.05f, -0.05f ); // -0.05%씩 보석이 축소되면서 사라지게 한다.
				}
				
			} else {
				if(stage.MapData.get(0).get(i).type == 9) {   // 버튼 
					if(Target != null && stage.MapData.get(0).get(i).crash == 0) {
						if(stage.MapData.get(0).get(i).CheckPos((int)Target.x, (int)Target.y)) {
							stage.MapData.get(0).get(i).AddFrame(0.2f);
							if(stage.MapData.get(0).get(i).frame >= 2) {
								stage.MapData.get(0).get(i).move = Const.STOP;
								if(StageNum == 19 || StageNum == 29) {
									bSpider = true;
								} else {
									distance = 22.5f;
									Temp1.x = x1;
									Temp1.y = y1;
									Temp1.delay = 0;
									Temp1.direct = 0;
									
									Temp2.x = x2;
									Temp2.y = y2;
									Temp2.delay = 0;
									Temp2.direct = 0;
									stage.MapData.get(0).get(i).crash = 1;
								}
							}
						}
					}
				} else if(stage.MapData.get(0).get(i).type == 11) {   // 레이저  
					if ( stage.MapData.get(0).get(i).crash == 0 )
					{
						stage.MapData.get(0).get(i).crash = 1;
						StartTimer = System.currentTimeMillis();
						stage.MapData.get(0).get(i).show = false;
					}
					int as = (int)((System.currentTimeMillis()-StartTimer) / 1000);
					if(as >= 2) {
						StartTimer = System.currentTimeMillis();
//						stage.MapData.get(0).get(i).crash = 0;
						if(stage.MapData.get(0).get(i).show  == true) stage.MapData.get(0).get(i).show = false ; else stage.MapData.get(0).get(i).show = true ;
					}
					if(stage.MapData.get(0).get(i).show) {
						if(Target != null) {
							if(stage.MapData.get(0).get(i).CheckPos((int)Target.x, (int)Target.y)) {
//								Target.move = Const.DEAD;
//								if(Tifo.effect_sound.equals("Y")) PlaySound( 3 );
//								tifoCount--;
								over = true;
							}
						}						
					}
				} else if(stage.MapData.get(0).get(i).type == 14) {   // 기둥
//					if(stage.MapData.get(0).get(i).current == 0) {
//						stage.MapData.get(0).get(i).y += 60;
//						stage.MapData.get(0).get(i).current = 1;
//					}
					stage.MapData.get(0).get(i).SetZoom(gInfo, 0.80f, 0.6f );

					stage.MapData.get(0).get(i).AddFrame(0.02f);
					if(stage.MapData.get(0).get(i).frame >= 20) {
						stage.MapData.get(0).get(i).frame = 0;
					}	
				} else if(stage.MapData.get(0).get(i).type >= 15 && stage.MapData.get(0).get(i).type <= 19) {   // 카트   
					setTreeMoving(stage.MapData.get(0).get(i));
					if(StageNum >= 15) {
						if ( stage.MapData.get(0).get(i).x1 >= gInfo.ScreenX) stage.MapData.get(0).get(i).x -= 940;				
						if ( stage.MapData.get(0).get(i).x1 <= 0 && stage.MapData.get(0).get(i).x1 <  -150)  stage.MapData.get(0).get(i).x += 950;				
						
					}

				} else if(stage.MapData.get(0).get(i).type == 20) {                                             // 펀치  

					stage.MapData.get(0).get(i).AddFrame(0.005f);
					if(stage.MapData.get(0).get(i).frame >= 2) {
						stage.MapData.get(0).get(i).frame = 0;
					}	
				} else if(stage.MapData.get(0).get(i).type == 21) {                                             // 거미 

					stage.MapData.get(0).get(i).AddFrame(0.2f);
					if(stage.MapData.get(0).get(i).frame >= 2) {
						stage.MapData.get(0).get(i).frame = 0;
					}	
					boolean x = false;
					boolean y = false;
					int x1 = 180;
					int x2 = 480;
					int y1 = 1064;
					int y2 = 1344;
					
					if(StageNum == 25) {
						x1 = 554;
						x2 = 705;
						y1 = 161;
						y2 = 318;
					}
					
					if(bSpider == false) {
						if(stage.MapData.get(0).get(i).x < x1) {
							stage.MapData.get(0).get(i).x += 1;
							stage.MapData.get(0).get(i).motion = 3;
						} else 	if(stage.MapData.get(0).get(i).x >= x2) {
							stage.MapData.get(0).get(i).x -= 1;
							stage.MapData.get(0).get(i).motion = 2;
						} else {
							x = true;
						}
						if(stage.MapData.get(0).get(i).y < y1) {
							stage.MapData.get(0).get(i).y += 1;
							stage.MapData.get(0).get(i).motion = 1;
						} else if(stage.MapData.get(0).get(i).y > y2) {
							stage.MapData.get(0).get(i).y -= 1;
							stage.MapData.get(0).get(i).motion = 0;

						} else {
							y = true;
						}
					} else {
						if(stage.MapData.get(0).get(i).x < 481) {
							stage.MapData.get(0).get(i).x += 1;
							stage.MapData.get(0).get(i).motion = 3;
						} else 	if(stage.MapData.get(0).get(i).x >= 660) {
							stage.MapData.get(0).get(i).x -= 1;
							stage.MapData.get(0).get(i).motion = 2;
						} else {
							x = true;
						}
						if(stage.MapData.get(0).get(i).y < 1134) {
							stage.MapData.get(0).get(i).y += 1;
							stage.MapData.get(0).get(i).motion = 1;
						} else if(stage.MapData.get(0).get(i).y > 1282) {
							stage.MapData.get(0).get(i).y -= 1;
							stage.MapData.get(0).get(i).motion = 0;

						} else {
							y = true;
						}
					}
					if(x == true) {
						if(stage.MapData.get(0).get(i).motion == 2) {
							stage.MapData.get(0).get(i).x -= 1;
						} else if(stage.MapData.get(0).get(i).motion == 3) {
							stage.MapData.get(0).get(i).x += 1;
						}
					}
					if(y == true) {
						if(stage.MapData.get(0).get(i).motion == 0) {
							stage.MapData.get(0).get(i).y -= 1;
						} else if(stage.MapData.get(0).get(i).motion == 1) {
							stage.MapData.get(0).get(i).y += 1;
						}
					}
					
					if(Target != null) {
						if(stage.MapData.get(0).get(i).CheckPos((int)Target.x, (int)Target.y)) {
							Target.move = Const.DEAD;
						}
					}						
				} else if(  stage.MapData.get(0).get(i).type == 22)   /////// 장애물(풍차)
				{
					stage.MapData.get(0).get(i).PutSprite( gInfo );
					stage.MapData.get(0).get(i).delay += 1;
					if(stage.MapData.get(0).get(i).delay >= 10) {
						stage.MapData.get(0).get(i).direct += 15;
						int endframe = 0;
						if(stage.MapData.get(0).get(i).motion == 0) endframe = 8;
						if(stage.MapData.get(0).get(i).motion == 1) endframe = 11;
						if(stage.MapData.get(0).get(i).motion == 2) endframe = 12;
						if(stage.MapData.get(0).get(i).motion == 3) endframe = 13;
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						if(stage.MapData.get(0).get(i).frame >= endframe) {
							stage.MapData.get(0).get(i).frame = 0;
						}	
						stage.MapData.get(0).get(i).delay = 0;
						
						if(Target != null) {
							Target.PutSprite( gInfo );
//							try {
								if(gInfo.BitmapCheck(Target, (byte)1, stage.MapData.get(0).get(i), (byte)1)) {
//									if(stage.MapData.get(0).get(i).CheckPos((int)Target.x, (int)Target.y)) {
										Target.move = Const.DEAD;
									}
//							} catch(Exception e) {}
						}
					}
				} else if(stage.MapData.get(0).get(i).type >= 30 && stage.MapData.get(0).get(i).type <= 39) {   // 통나무 이동 
					
					setTreeMoving(stage.MapData.get(0).get(i));
					
					stage.MapData.get(0).get(i).AddFrame(0.2f);
					if(stage.MapData.get(0).get(i).frame >= 3) {
						stage.MapData.get(0).get(i).frame = 0;
					}	
					if (StageNum >= 26) {  /// 빙하에서 좌우 방향이 끝어지는 현상이 있어서 
						if ( stage.MapData.get(0).get(i).x1 >= gInfo.ScreenX ) stage.MapData.get(0).get(i).x -= 1040;				
						if ( stage.MapData.get(0).get(i).x1 <= 0 && stage.MapData.get(0).get(i).x1 <  -250)  stage.MapData.get(0).get(i).x += 1030;				
					} else {
						if ( stage.MapData.get(0).get(i).x1 >= gInfo.ScreenX ) stage.MapData.get(0).get(i).x -= 940;				
						if ( stage.MapData.get(0).get(i).x1 <= 0 && stage.MapData.get(0).get(i).x1 <  -150)  stage.MapData.get(0).get(i).x += 890;				
					}
				} else if(  stage.MapData.get(0).get(i).type >= 52 &&  stage.MapData.get(0).get(i).type <= 55)   // 장애물(나무  )
				{
					stage.MapData.get(0).get(i).AddFrame(0.02f);
					if(stage.MapData.get(0).get(i).motion == 0 || stage.MapData.get(0).get(i).motion == 1) {
						if(stage.MapData.get(0).get(i).frame >= 8) {
							stage.MapData.get(0).get(i).frame = 0;
						}	
					} else {
						if(stage.MapData.get(0).get(i).frame >= 4) {
							stage.MapData.get(0).get(i).frame = 0;
						}	
						
					}
				} else if(  stage.MapData.get(0).get(i).type == 60 )   // 장애물(톱니 )
				{
					stage.MapData.get(0).get(i).AddFrame(0.02f);
					if(stage.MapData.get(0).get(i).frame >= 6) {
						stage.MapData.get(0).get(i).frame = 0;
					}	
				} else if(  stage.MapData.get(0).get(i).type == 61 ||  (stage.MapData.get(0).get(i).type >= 41 && stage.MapData.get(0).get(i).type <= 43))   // 거북이 
				{
					setTreeMoving(stage.MapData.get(0).get(i));
					stage.MapData.get(0).get(i).PutSprite( gInfo );
					
					if(stage.MapData.get(0).get(i).move == Const.DIVE) {
						if(gebukMontion == 10) 	stage.MapData.get(0).get(i).motion = 11; else stage.MapData.get(0).get(i).motion = 9;
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						if(stage.MapData.get(0).get(i).frame >= 5) {
							stage.MapData.get(0).get(i).frame = 0;
//							Target.move = Const.DEAD;
							
							int motion = 0;
							if(Target.motion == 0) {
								motion = Target.motion;
							} else if(Target.motion == 1) {
								motion = 3;
							} else if(Target.motion == 2) {
								motion = 1;
							} else if(Target.motion == 3) {
								motion = 2;
							}
							MakeBomb( Target.x, Target.y, Target.type, true, motion, 0, 5); 
							stage.MapData.get(0).remove( i-- );

						}
					} else {
						if(stage.MapData.get(0).get(i).crash == 0) {
							gebukMontion = stage.MapData.get(0).get(i).motion;
							stage.MapData.get(0).get(i).crash  = 1;
						}
						stage.MapData.get(0).get(i).motion = gebukMontion;
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						if(stage.MapData.get(0).get(i).frame >= 8) {
							stage.MapData.get(0).get(i).frame = 0;
						}	
					}
					
					if ( stage.MapData.get(0).get(i).x1 >= gInfo.ScreenX ) stage.MapData.get(0).get(i).x -= 940;				
					if ( stage.MapData.get(0).get(i).x1 <= 0 && stage.MapData.get(0).get(i).x1 <  -150)  stage.MapData.get(0).get(i).x += 890;	
				} else if(  stage.MapData.get(0).get(i).type >= 63 &&  stage.MapData.get(0).get(i).type <= 64)   // 물고기 
				{
					setTreeMoving(stage.MapData.get(0).get(i));
					GameObject nowPostionStat = GetNowPositionStatus2((int)stage.MapData.get(0).get(i).x, (int)stage.MapData.get(0).get(i).y);  // 다른 장애물이 있는지
					if(nowPostionStat != null && nowPostionStat.type != 63 && nowPostionStat.type != 64) {  // 물고기가 발판을 맞았을때 모션을 변경해 준다
						int motion = 0;
						if(stage.MapData.get(0).get(i).motion == 4) {
							motion = 7;
						} else if(stage.MapData.get(0).get(i).motion == 5) {
							motion = 6;
						}  else {
							motion = stage.MapData.get(0).get(i).motion;
						}
						stage.MapData.get(0).get(i).motion = motion;
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						if(stage.MapData.get(0).get(i).frame >= 5) {
							stage.MapData.get(0).get(i).frame = 0;
							if(stage.MapData.get(0).get(i).motion == 7) {
								stage.MapData.get(0).get(i).motion = 4;
							} else if(stage.MapData.get(0).get(i).motion == 6) {
								stage.MapData.get(0).get(i).motion = 5;
							}
						}	
						
						if(Target != null) {
							if(stage.MapData.get(0).get(i).CheckPos((int)Target.x, (int)Target.y)) {
								Target.move = Const.DEAD;
							}
						}
					} else {
						if(stage.MapData.get(0).get(i).motion == 7) {
							stage.MapData.get(0).get(i).motion = 4;
						} else if(stage.MapData.get(0).get(i).motion == 6) {
							stage.MapData.get(0).get(i).motion = 5;
						}
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						if(stage.MapData.get(0).get(i).frame >= 2) {
							stage.MapData.get(0).get(i).frame = 0;
						}							
					}

					if ( stage.MapData.get(0).get(i).x1 >= gInfo.ScreenX ) stage.MapData.get(0).get(i).x -= 940;				
					if ( stage.MapData.get(0).get(i).x1 <= 0 && stage.MapData.get(0).get(i).x1 <  -150)  stage.MapData.get(0).get(i).x += 890;	
					
				} else if(  stage.MapData.get(0).get(i).type == 62 )   // 장애물(송곳)
				{
					float f1 = 0.008f;
					float f2 = 0.05f;
					if(StageNum == 12) {
						f1 = 0.0002f;
						f2 = 0.005f;
					}
					if(stage.MapData.get(0).get(i).frame <= 1 || stage.MapData.get(0).get(i).frame >= 7) {
						stage.MapData.get(0).get(i).AddFrame(f1);
					} else {
						stage.MapData.get(0).get(i).AddFrame(f2);
					}
					if(stage.MapData.get(0).get(i).frame >= 8) {
						stage.MapData.get(0).get(i).frame = 0;
					}					
				} else if(  stage.MapData.get(0).get(i).type >= 90 && stage.MapData.get(0).get(i).type <= 91)   /////// 장애물(벌)
				{
					if(stage.MapData.get(0).get(i).crash == 0 && stage.MapData.get(0).get(i).type == 90) {
						stage.MapData.get(0).get(i).crash = 1;
						x1 = stage.MapData.get(0).get(i).x;
						y1 = stage.MapData.get(0).get(i).y;
						Temp1 = stage.MapData.get(0).get(i);
					}
					if(stage.MapData.get(0).get(i).crash == 0 && stage.MapData.get(0).get(i).type == 91) {
						stage.MapData.get(0).get(i).crash = 1;
						x2 = stage.MapData.get(0).get(i).x;
						y2 = stage.MapData.get(0).get(i).y;
						Temp2 = stage.MapData.get(0).get(i);
					}					
					stage.MapData.get(0).get(i).delay += 1;
					if(stage.MapData.get(0).get(i).delay >= 15) {
						stage.MapData.get(0).get(i).direct += 15;
						if(stage.MapData.get(0).get(i).direct >= 360) stage.MapData.get(0).get(i).direct = 0;
						if(stage.MapData.get(0).get(i).direct >= 260 && stage.MapData.get(0).get(i).direct < 0) stage.MapData.get(0).get(i).motion = 0;
						if(stage.MapData.get(0).get(i).direct >= 0 || stage.MapData.get(0).get(i).direct < 30) stage.MapData.get(0).get(i).motion = 1;
						if(stage.MapData.get(0).get(i).direct >= 30  && stage.MapData.get(0).get(i).direct < 60) stage.MapData.get(0).get(i).motion = 2;
						if(stage.MapData.get(0).get(i).direct >= 60  && stage.MapData.get(0).get(i).direct < 260) stage.MapData.get(0).get(i).motion = 3;
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						if(stage.MapData.get(0).get(i).frame >= 2) {
							stage.MapData.get(0).get(i).frame = 0;
						}	
						stage.MapData.get(0).get(i).MovebyAngle( gInfo, stage.MapData.get(0).get(i).direct, distance);	
						stage.MapData.get(0).get(i).delay = 0;
						
						if(Target != null) {
							if(stage.MapData.get(0).get(i).CheckPos((int)Target.x, (int)Target.y)) {
								Target.move = Const.DEAD;
							}
						}
					}
				} else if(  stage.MapData.get(0).get(i).type >= 81 &&  stage.MapData.get(0).get(i).type <= 84)   // 대포  
				{
					float f = 0.02f;
					if(StageNum == 12 || StageNum == 14) f = 0.006f;
					stage.MapData.get(0).get(i).AddFrame(f);
					if(stage.MapData.get(0).get(i).frame >= 10) {
						stage.MapData.get(0).get(i).frame = 0;
						int motion = 0;
						if(stage.MapData.get(0).get(i).motion == 0) {
							motion = 1;
						} else if(stage.MapData.get(0).get(i).motion == 2) {
							motion = 3;
						} else if(stage.MapData.get(0).get(i).motion == 4) {
							motion = 5;
						} else if(stage.MapData.get(0).get(i).motion == 6) {
							motion = 7;
						}
						float x = 0;
						float y = 0;
						if(stage.MapData.get(0).get(i).type == 81) { x = stage.MapData.get(0).get(i).x - 30; y = stage.MapData.get(0).get(i).y; }
						if(stage.MapData.get(0).get(i).type == 82) { x = stage.MapData.get(0).get(i).x + 30; y = stage.MapData.get(0).get(i).y; }
						if(stage.MapData.get(0).get(i).type == 83) { x = stage.MapData.get(0).get(i).x; y = stage.MapData.get(0).get(i).y + 30; }
						if(stage.MapData.get(0).get(i).type == 84) { x = stage.MapData.get(0).get(i).x; y = stage.MapData.get(0).get(i).y - 30; }
						MakeBomb( x, y, stage.MapData.get(0).get(i).type, true, motion, 0, 0); // 대포 생성 
					}	
				} else if((stage.MapData.get(0).get(i).type >= 85 && stage.MapData.get(0).get(i).type <= 88) || stage.MapData.get(0).get(i).type == 92|| stage.MapData.get(0).get(i).type == 93)   // 번개 대포   
				{
					stage.MapData.get(0).get(i).AddFrame(0.02f);
					float x = 0;
					float y = 0;
					int motion = 0;
					int type = 0;

					if(stage.MapData.get(0).get(i).type == 85) { x = stage.MapData.get(0).get(i).x; y = stage.MapData.get(0).get(i).y + 180; motion = 7; type = 89;}
					if(stage.MapData.get(0).get(i).type == 87) { x = stage.MapData.get(0).get(i).x+ 210; y = stage.MapData.get(0).get(i).y+ 20; motion = 6; type = 89;}
					if(stage.MapData.get(0).get(i).type == 92) { x = stage.MapData.get(0).get(i).x; y = stage.MapData.get(0).get(i).y + 180; motion = 7; type = 89;}
					if(stage.MapData.get(0).get(i).type == 93) { x = stage.MapData.get(0).get(i).x-160; y = stage.MapData.get(0).get(i).y+14; motion = 6; type = 89;}
					if(stage.MapData.get(0).get(i).frame >= 3 && stage.MapData.get(0).get(i).frame < 4) {
						
						if(stage.MapData.get(0).get(i).type == 85 || stage.MapData.get(0).get(i).type == 87)  {
							stage.MapData.get(0).get(i).delay += 1;
							if(stage.MapData.get(0).get(i).delay >= 15) { 
								MakeBomb( x, y, type, true, motion, 0, 0);
								stage.MapData.get(0).get(i).delay = 0; 
							}  // 대포 생성 
						}
						if(stage.MapData.get(0).get(i).type == 92) {
							stage.MapData.get(0).get(i).delay += 1;
							if(stage.MapData.get(0).get(i).delay >= 15) { 
								MakeBomb( x, y, type, true, motion, 0, 0); // 대포 생성 
								MakeBomb( x, 40, type, true, motion, 0, 0); // 대포 생성 
								stage.MapData.get(0).get(i).delay = 0; 
							}
						}
						if(stage.MapData.get(0).get(i).type == 93) {
							stage.MapData.get(0).get(i).delay += 1;
							if(stage.MapData.get(0).get(i).delay >= 15) { 
								MakeBomb( x, y, type, true, motion, 0, 0); // 대포 생성 
								MakeBomb( x+372, y, type, true, motion, 0, 0); // 대포 생성 
								stage.MapData.get(0).get(i).delay = 0; 
							}
						}
					}
					if(stage.MapData.get(0).get(i).frame >= 4) {
						if(stage.MapData.get(0).get(i).type == 92 || stage.MapData.get(0).get(i).type == 93) {
							stage.MapData.get(0).get(i).delay += 1;
							if(stage.MapData.get(0).get(i).delay >= 40) {
								stage.MapData.get(0).get(i).delay = 0;
								stage.MapData.get(0).get(i).frame = 0;
							}
						} else {
							stage.MapData.get(0).get(i).frame = 0;
						}
					}	
				} else if(  stage.MapData.get(0).get(i).type == 40 )   // 나무 발판(스테이즈 15)  
				{
					if(stage.MapData.get(0).get(i).move == Const.FALL )
					{
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						if(stage.MapData.get(0).get(i).frame >= 2) {
							stage.MapData.get(0).get(i).delay += 1;
							if(stage.MapData.get(0).get(i).delay >= 15) {
								stage.MapData.get(0).get(i).delay = 0;
								stage.MapData.get(0).get(i).move = Const.STOP;
								stage.MapData.get(0).get(i).frame = 0;
								Target.move = Const.DEAD;
							}
						}					
					}
				} else if(  stage.MapData.get(0).get(i).type == 50 )   // 무너진 발판 
				{
					if(stage.MapData.get(0).get(i).move == Const.FALL)
					{
						if(StageNum < 21) {
							stage.MapData.get(0).get(i).motion = 2;
							stage.MapData.get(0).get(i).AddFrame(0.2f);
							if(stage.MapData.get(0).get(i).frame >= 4) {
								stage.MapData.get(0).get(i).move = Const.STOP;
								stage.MapData.get(0).get(i).frame = 0;
								Target.move = Const.DEAD;
							}
							
						} else {
							stage.MapData.get(0).get(i).AddFrame(0.2f);
							if(stage.MapData.get(0).get(i).frame >= 8) {
								stage.MapData.get(0).get(i).move = Const.STOP;
								stage.MapData.get(0).get(i).frame = 0;
								Target.move = Const.DEAD;
							}							
						}
					}
				} else if(  stage.MapData.get(0).get(i).type == 51 )   // 무너진 돌판 
				{
					if(stage.MapData.get(0).get(i).move == Const.FALL )
					{
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						if(stage.MapData.get(0).get(i).frame >= 2) {
							stage.MapData.get(0).get(i).move = Const.STOP;
							stage.MapData.get(0).get(i).frame = 0;
							Target.move = Const.DEAD;
						}					
					}
				} else if(  stage.MapData.get(0).get(i).type == 71 )   // 용암대포  
				{
					stage.MapData.get(0).get(i).AddFrame(0.02f);
					if(stage.MapData.get(0).get(i).frame >= 12) {
						stage.MapData.get(0).get(i).frame = 0;
					}					
				} else if(  stage.MapData.get(0).get(i).type == 72 )   // 용암 
				{
					stage.MapData.get(0).get(i).AddFrame(0.02f);
					if(stage.MapData.get(0).get(i).frame >= 7) {
						stage.MapData.get(0).get(i).frame = 0;
					}					
				} else if(  stage.MapData.get(0).get(i).type == 73 )   // 용암 
				{
					stage.MapData.get(0).get(i).AddFrame(0.02f);
					if(stage.MapData.get(0).get(i).frame >= 6) {
						stage.MapData.get(0).get(i).frame = 0;
					}					
				} else if(  stage.MapData.get(0).get(i).type == 94 )   // 대포2 
				{
					int motion = 0;
					float x = 0;
					float y = 0;
					if(stage.MapData.get(0).get(i).motion == 0) {
						motion = 1;
						x = stage.MapData.get(0).get(i).x - 80;
						y = stage.MapData.get(0).get(i).y;
					} else if(stage.MapData.get(0).get(i).motion == 2) {
						motion = 3;
						x = stage.MapData.get(0).get(i).x + 80;
						y = stage.MapData.get(0).get(i).y;
					} else if(stage.MapData.get(0).get(i).motion == 4) {
						motion = 5;
						x = stage.MapData.get(0).get(i).x + 8;
						y = stage.MapData.get(0).get(i).y - 76;
					} else if(stage.MapData.get(0).get(i).motion == 6) {
						motion = 7;
						x = stage.MapData.get(0).get(i).x + 4;
						y = stage.MapData.get(0).get(i).y + 76;
					}
					stage.MapData.get(0).get(i).AddFrame(0.02f);
					if(stage.MapData.get(0).get(i).frame >= 8) {
						MakeBomb( x, y, stage.MapData.get(0).get(i).type, true, motion, 0, 0); // 대포 생성 
						stage.MapData.get(0).get(i).frame = 0;
					}	
				} else if(  stage.MapData.get(0).get(i).type == 95 )   // 트레스 포트
				{
					stage.MapData.get(0).get(i).AddFrame(0.2f);
					if(stage.MapData.get(0).get(i).frame >= 22) {
						stage.MapData.get(0).get(i).frame = 0;
					}	
					int x = 0;
					int y = 0;
					if(StageNum == 17 && stage.MapData.get(0).get(i).x == 415 && stage.MapData.get(0).get(i).y == 2730) {
						x = 210;
						y = 2050;
					} else if(StageNum == 17 && stage.MapData.get(0).get(i).x == 601 && stage.MapData.get(0).get(i).y == 1690) {
						x = 440;
						y = 535;
					} else if(StageNum == 18 && stage.MapData.get(0).get(i).x == 300 && stage.MapData.get(0).get(i).y == 1512) {
						x = 450;
						y = 430;
					}
					if(Target != null) {
						if(stage.MapData.get(0).get(i).CheckPos((int)Target.x, (int)Target.y)) {
							if(x != 0) {
								Target.x = x;
								Target.y = y;
								left_right = false;
								Target.move = Const.STOP;
								Moving = false;
								Target.frame = 0;
//								Target.trans = 0.0f;
							} else {
//								Target.trans += 0.0033f; // 투명도를 0으로 설정해서 서서히 밝아지도록 한다.
							}
						}
					}
				} else if(  stage.MapData.get(0).get(i).type == 96 || stage.MapData.get(0).get(i).type == 97)   /////// 장애물(박쥐)
				{
					if(stage.MapData.get(0).get(i).crash == 0 ) {
						stage.MapData.get(0).get(i).crash = 1;
						x1 = stage.MapData.get(0).get(i).x;
						y1 = stage.MapData.get(0).get(i).y;
						Temp1 = stage.MapData.get(0).get(i);
					}
					stage.MapData.get(0).get(i).delay += 1;
					if(stage.MapData.get(0).get(i).delay >= 15) {
						stage.MapData.get(0).get(i).direct += 15;
						if(stage.MapData.get(0).get(i).direct >= 360) stage.MapData.get(0).get(i).direct = 0;
						if(stage.MapData.get(0).get(i).direct >= 260 && stage.MapData.get(0).get(i).direct < 0) stage.MapData.get(0).get(i).motion = 1;
						if(stage.MapData.get(0).get(i).direct >= 0 || stage.MapData.get(0).get(i).direct < 30) stage.MapData.get(0).get(i).motion = 1;
						if(stage.MapData.get(0).get(i).direct >= 30  && stage.MapData.get(0).get(i).direct < 60) stage.MapData.get(0).get(i).motion = 2;
						if(stage.MapData.get(0).get(i).direct >= 60  && stage.MapData.get(0).get(i).direct < 260) stage.MapData.get(0).get(i).motion = 3;
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						if(stage.MapData.get(0).get(i).frame >= 6) {
							stage.MapData.get(0).get(i).frame = 0;
						}	
						float d = 0f;
						if(stage.MapData.get(0).get(i).type == 96) d= 18f;
						if(stage.MapData.get(0).get(i).type == 97) d= -18f;
						stage.MapData.get(0).get(i).MovebyAngle( gInfo, stage.MapData.get(0).get(i).direct, d);	
						stage.MapData.get(0).get(i).delay = 0;
						
						if(Target != null) {
							if(stage.MapData.get(0).get(i).CheckPos((int)Target.x, (int)Target.y)) {
								Target.move = Const.DEAD;
							}
						}
					}
				} else if(stage.MapData.get(0).get(i).type == 98) {                                             // 곰  

					stage.MapData.get(0).get(i).AddFrame(0.02f);
					if(stage.MapData.get(0).get(i).frame >= 2) {
						stage.MapData.get(0).get(i).frame = 0;
					}	
					boolean x = false;
					boolean y = false;
					int x1 = 296;
					int x2 = 617;
					int y1 = 2399;
					int y2 = 2891;
					
					if(StageNum == 29) {
						x1 = 192;
						x2 = 448;
						y1 = 469;
						y2 = 674;
					}

					if(stage.MapData.get(0).get(i).x < x1) {
						stage.MapData.get(0).get(i).x += 1;
						stage.MapData.get(0).get(i).motion = 0;
					} else 	if(stage.MapData.get(0).get(i).x >= x2) {
						stage.MapData.get(0).get(i).x -= 1;
						stage.MapData.get(0).get(i).motion = 1;
					} else {
						x = true;
					}
					if(stage.MapData.get(0).get(i).y < y1) {
						stage.MapData.get(0).get(i).y += 1;
						stage.MapData.get(0).get(i).motion = 2;
					} else if(stage.MapData.get(0).get(i).y > y2) {
						stage.MapData.get(0).get(i).y -= 1;
						stage.MapData.get(0).get(i).motion = 3;

					} else {
						y = true;
					}

					if(x == true) {
						if(stage.MapData.get(0).get(i).motion == 1) {
							stage.MapData.get(0).get(i).x -= 1;
						} else if(stage.MapData.get(0).get(i).motion == 0) {
							stage.MapData.get(0).get(i).x += 1;
						}
					}
					if(y == true) {
						if(stage.MapData.get(0).get(i).motion == 3) {
							stage.MapData.get(0).get(i).y -= 1;
						} else if(stage.MapData.get(0).get(i).motion == 2) {
							stage.MapData.get(0).get(i).y += 1;
						}
					}
					
					if(Target != null) {
						if(stage.MapData.get(0).get(i).CheckPos((int)Target.x, (int)Target.y)) {
							Target.move = Const.DEAD;
						}
					}						
				} else if(  stage.MapData.get(0).get(i).type >= 3 && stage.MapData.get(0).get(i).type <= 8)   // 달러 
				{
					if(StageNum == 17) {
						setTreeMoving(stage.MapData.get(0).get(i));
						if ( stage.MapData.get(0).get(i).x1 >= gInfo.ScreenX) stage.MapData.get(0).get(i).x -= 940;				
						if ( stage.MapData.get(0).get(i).x1 <= 0 && stage.MapData.get(0).get(i).x1 <  -150)  stage.MapData.get(0).get(i).x += 950;				
				
					}

					if(Target != null) {
						if(stage.MapData.get(0).get(i).CheckPos((int)Target.x, (int)Target.y) && Target.move == Const.STOP) {
							/// 달러 3, 별 4, 하트 5, 깃발 6
							if(stage.MapData.get(0).get(i).type == 5) {
								hartNum += 10;
							} else {
								pointNum += stage.MapData.get(0).get(i).type;	
							}
							MakeEffect( stage.MapData.get(0).get(i).x, stage.MapData.get(0).get(i).y, 20, true ); // 불꽃 이펙트 생성
							if(Tifo.effect_sound.equals("Y")) PlaySound( 1 );
							
							stage.MapData.get(0).get(i).move = Const.DEAD;
						}
					}
				} else if(  stage.MapData.get(0).get(i).type == 0)   // 정상 발판 
				{
					if(stage.MapData.get(0).get(i).move == Const.FALL )
					{
//						stage.MapData.get(0).get(i).motion = 1;
						stage.MapData.get(0).get(i).AddFrame(0.1f);
						if(stage.MapData.get(0).get(i).frame >= 5) {
							stage.MapData.get(0).get(i).move = Const.STOP;
							stage.MapData.get(0).get(i).frame = 0;
						}					
					}
			    /////////////////////////////////////////////////////////////////////////////////////// 
				} else if ( stage.MapData.get(0).get(i).type == 100 )   /////////////////////////////// 티포 
				{
					if(stage.MapData.get(0).get(i).move == Const.RIGHT) {
						stage.MapData.get(0).get(i).y -= stage.MapData.get(0).get(i).power / 100;
						stage.MapData.get(0).get(i).power -= 30;
						
						stage.MapData.get(0).get(i).motion = 2;
						stage.MapData.get(0).get(i).x += 2;
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						Moving = true;
						if(stage.MapData.get(0).get(i).x >= stage.MapData.get(0).get(i).ox) {
							stage.MapData.get(0).get(i).x = stage.MapData.get(0).get(i).ox;
							stage.MapData.get(0).get(i).move = Const.STOP;
							stage.MapData.get(0).get(i).frame = 0;
							stage.MapData.get(0).get(i).y =  stage.MapData.get(0).get(i).oy;
							Moving = false;

						}					
					} else if(stage.MapData.get(0).get(i).move == Const.UP) {
						stage.MapData.get(0).get(i).motion = 1;
						stage.MapData.get(0).get(i).y -= 2;
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						Moving = true;
						if(stage.MapData.get(0).get(i).y <= stage.MapData.get(0).get(i).oy) {
							stage.MapData.get(0).get(i).y = stage.MapData.get(0).get(i).oy;
							stage.MapData.get(0).get(i).move = Const.STOP;
							stage.MapData.get(0).get(i).frame = 0;
							Moving = false;
						}
					} else if(stage.MapData.get(0).get(i).move == Const.LEFT) {
						stage.MapData.get(0).get(i).y -= stage.MapData.get(0).get(i).power / 100;
						stage.MapData.get(0).get(i).power -= 30;
						
						stage.MapData.get(0).get(i).motion = 3;
						stage.MapData.get(0).get(i).x -= 2;
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						Moving = true;
						if(stage.MapData.get(0).get(i).x <= stage.MapData.get(0).get(i).ox) {
							stage.MapData.get(0).get(i).x = stage.MapData.get(0).get(i).ox;
							stage.MapData.get(0).get(i).move = Const.STOP;
							stage.MapData.get(0).get(i).frame = 0;
							stage.MapData.get(0).get(i).y =  stage.MapData.get(0).get(i).oy;
							Moving = false;
						}
					} else if(stage.MapData.get(0).get(i).move == Const.DOWN) {
						stage.MapData.get(0).get(i).motion = 0;
						stage.MapData.get(0).get(i).y += 2;
						stage.MapData.get(0).get(i).AddFrame(0.2f);
						Moving = true;
						if(stage.MapData.get(0).get(i).y >= stage.MapData.get(0).get(i).oy) {
							stage.MapData.get(0).get(i).y = stage.MapData.get(0).get(i).oy;
							stage.MapData.get(0).get(i).move = Const.STOP;
							stage.MapData.get(0).get(i).frame = 0;
							Moving = false;
						}
					} else if(stage.MapData.get(0).get(i).move == Const.STOP && Moving == false) {
		     			if ( stage.MapData.get(0).get(i).trans >= 1 ) // 로고가 모두 나타났으면
		    			{		
		     				 stage.MapData.get(0).get(i).trans = 1;
		    			}
						if((int)stage.MapData.get(0).get(i).y > stage.MapScrollY) stage.MapData.get(0).get(i).y = stage.MapData.get(0).get(i).y - 56;
						if((int)stage.MapData.get(0).get(i).y <= 0) stage.MapData.get(0).get(i).y = stage.MapData.get(0).get(i).y + 56;
						GameObject nowPostionStat = GetNowPositionStatus((int)stage.MapData.get(0).get(i).x, (int)stage.MapData.get(0).get(i).y);  //통나무 

						
						if(nowPostionStat != null) {
							if(nowPostionStat.type == 99 && stage.MapData.get(0).get(i).x >= 740) stage.MapData.get(0).get(i).x = stage.MapData.get(0).get(i).x - 60;
							if(nowPostionStat.type == 99 && stage.MapData.get(0).get(i).x <= 60) stage.MapData.get(0).get(i).x = stage.MapData.get(0).get(i).x + 60;
						}
						
						///// 티포의 경계선 범위 
						if((stage.MapData.get(0).get(i).x > 800 || stage.MapData.get(0).get(i).x < 0) && (StageNum < 11 || (StageNum >= 15 && StageNum <= 20) || StageNum >= 26)) {
						 	stage.MapData.get(0).get(i).move = Const.DEAD;
						} else if( (StageNum >= 21 && StageNum <= 25) && stage.MapData.get(0).get(i).x < 0) {
							stage.MapData.get(0).get(i).x = stage.MapData.get(0).get(i).x + 60;
						}
						
						//////  스테이즈15 펀치 예외사항이 발생해서 추가한 로직 
						for ( int ii = 0; ii < stage.MapData.get(0).size(); ii++ )
						{
							if ( stage.MapData.get(0).get(ii).type == 20 || stage.MapData.get(0).get(ii).type == 2 || stage.MapData.get(0).get(ii).type == 14 || stage.MapData.get(0).get(ii).type == 60)
							{
								if(stage.MapData.get(0).get(ii).CheckPos((int)stage.MapData.get(0).get(i).x, (int)stage.MapData.get(0).get(i).y)) {
									nowPostionStat = stage.MapData.get(0).get(ii);
								}
							}
						}
						if(nowPostionStat != null) {
//							System.out.println(" ============= " + nowPostionStat.type);
							if(nowPostionStat.type >= 30 && nowPostionStat.type <= 39)  {  // 통나무 i
//								System.out.println(Target.x + " .... " + Target.y + " ... " + Target.GetXsize()  + "..." + Target.GetYsize() + " >>>> " + nowPostionStat.GetXsize() +  " .... " + nowPostionStat.GetYsize() + " >>>> " + nowPostionStat.x + " ... " + nowPostionStat.y);
//
								UpdatePlayerPostion(nowPostionStat, nowPostionStat.type);
								setTifoWithTreeMoving(stage.MapData.get(0).get(i), nowPostionStat);
							} else if(nowPostionStat.type >= 15 && nowPostionStat.type <= 19) { // 카트 
								UpdatePlayerPostion(nowPostionStat, nowPostionStat.type);
								setTifoWithTreeMoving(stage.MapData.get(0).get(i), nowPostionStat);
							} else if(nowPostionStat.type == 61 || (stage.MapData.get(0).get(i).type >= 41 && stage.MapData.get(0).get(i).type <= 43)) { // 거북이
								UpdatePlayerPostion(nowPostionStat, nowPostionStat.type);
								setTifoWithTreeMoving(stage.MapData.get(0).get(i), nowPostionStat);
								if ( stage.MapData.get(0).get(i).crash == 0 )
								{
									stage.MapData.get(0).get(i).crash = 1;
									StartTimer = System.currentTimeMillis();
								}
								int as = (int)((System.currentTimeMillis()-StartTimer) / 1000);
								if(as >= 2) {
									stage.MapData.get(0).get(i).crash = 0;
									nowPostionStat.move = Const.DIVE;
								}								
							} else if(nowPostionStat.type == 10) { // 돌  발판  
								UpdatePlayerPostion(nowPostionStat, nowPostionStat.type);
							} else if(nowPostionStat.type == 14) { // 기둥 
								if(nowPostionStat.frame >= 0 && nowPostionStat.frame <= 3) {
									
									if(pre_status == Const.RIGHT) {
										Target.crash = 0;
										Target.attack = 0;
										Target.move = Const.LEFT; // 보석의 move 값을 왼쪽으로 설정
										Target.ox = Target.x - 60; // 보석의 목적 X좌표를 현재 좌표 -80으로 설정한다.
										Target.power = 400;			
										Target.oy = Target.y;
										left_right = true;
									} else if(pre_status == Const.LEFT) {
										Target.crash = 0;
										Target.attack = 0;
										Target.move = Const.RIGHT; // 보석의 move 값을 왼쪽으로 설정
										Target.ox = Target.x + 60; // 보석의 목적 X좌표를 현재 좌표 -80으로 설정한다.
										Target.power = 400;			
										Target.oy = Target.y;
										left_right = true;
									}
								}
							} else if(nowPostionStat.type == 40) { // 나무 발판 (스테이즈 15번)  
								if ( stage.MapData.get(0).get(i).crash == 0 )
								{
									stage.MapData.get(0).get(i).crash = 1;
									StartTimer = System.currentTimeMillis();
								}
								int as = (int)((System.currentTimeMillis()-StartTimer) / 1000);
								if(as >= 2) {
									stage.MapData.get(0).get(i).crash = 0;
									nowPostionStat.move = Const.FALL;
								}
							} else if(nowPostionStat.type == 20) { // 펀치   
								stage.MapData.get(0).get(i).move = Const.DEAD;
							} else if(nowPostionStat.type == 50) { // 무너진 발판  
								if ( stage.MapData.get(0).get(i).crash == 0 )
								{
									stage.MapData.get(0).get(i).crash = 1;
									StartTimer = System.currentTimeMillis();
								}
								int as = (int)((System.currentTimeMillis()-StartTimer) / 1000);
								if(as >= 3) {
									stage.MapData.get(0).get(i).crash = 0;
									nowPostionStat.move = Const.FALL;
								}
							} else if(nowPostionStat.type == 51) { // 무너진 돌판   
								if ( stage.MapData.get(0).get(i).crash == 0 )
								{
									stage.MapData.get(0).get(i).crash = 1;
									StartTimer = System.currentTimeMillis();
								}
								int as = (int)((System.currentTimeMillis()-StartTimer) / 1000);
								if(as >= 3) {
									stage.MapData.get(0).get(i).crash = 0;
									nowPostionStat.move = Const.FALL;
								}
							} else if(nowPostionStat.type == 60) { // 톱니
								if ( nowPostionStat.frame >= 2 &&  nowPostionStat.frame <= 4)
								{
									stage.MapData.get(0).get(i).move = Const.DEAD;
								}
							} else if(nowPostionStat.type == 62) { // 송곳
								if ( nowPostionStat.frame >= 2 &&  nowPostionStat.frame <= 6)
								{
									stage.MapData.get(0).get(i).move = Const.DEAD;
								}
							} else if(nowPostionStat.type == 12) { // 구멍 
								stage.MapData.get(0).get(i).move = Const.DEAD;
							} else if(nowPostionStat.type >= 63 && nowPostionStat.type <= 64 ) { // 물고기 
								stage.MapData.get(0).get(i).move = Const.DEAD;
							} else if(nowPostionStat.type == 73 || nowPostionStat.type == 72 || nowPostionStat.type == 71) { // 용암 
								stage.MapData.get(0).get(i).move = Const.DEAD;
							} else if(nowPostionStat.type == 89 && nowPostionStat.show) { // 번개  
								stage.MapData.get(0).get(i).move = Const.DEAD;
							} else if(nowPostionStat.type >= 52 && nowPostionStat.type <= 55) { // (장애물 나무 ) 
								stage.MapData.get(0).get(i).move = Const.DEAD;
//							} else if(nowPostionStat.type == 0 && ((StageNum >= 15 && StageNum <= 25) || StageNum >= 28)) { // 15스테이즈에서 절벽 
							} else if(nowPostionStat.type == 0 && ((StageNum >= 15 && StageNum <= 25))) { // 15스테이즈에서 절벽 
								stage.MapData.get(0).get(i).move = Const.DEAD;
							} else if(  nowPostionStat.type >= 3 && nowPostionStat.type <= 8)   // 달러 
							{
								if(nowPostionStat.CheckPos((int)stage.MapData.get(0).get(i).x, (int)stage.MapData.get(0).get(i).y) && stage.MapData.get(0).get(i).move == Const.STOP) {
									/// 달러 3, 별 4, 하트 5, 깃발 6
									if(nowPostionStat.type == 5) {
										hartNum += 10;
									} else {
										pointNum += nowPostionStat.type;	
									}
									MakeEffect( nowPostionStat.x, nowPostionStat.y, 20, true ); // 불꽃 이펙트 생성
									if(Tifo.effect_sound.equals("Y")) PlaySound( 1 );
									
									nowPostionStat.move = Const.DEAD;
								}
							} else if(nowPostionStat.type == 0) { // 정상적인 발판 
								nowPostionStat.move = Const.FALL;
							} else if(  nowPostionStat.type == 2)   // 목표지점  
							{
								StageNum++;
								bGameOver =  true;
						        pre_pointNum = pointNum;
						        pre_hartNum  = hartNum;
						        if(StageNum > currentLevel) {
						        	currentLevel = StageNum;
						        	Tifo.setLevel(currentLevel);
						        }
								motion = MyRand.nextInt(4);
								f = 0;
								GameMode = 86;
						        ///////// 가족상봉 ////////////
						        if(StageNum >= 30) {
									GameMode = 89;
						        }
							}

						} else
						{
							if(checkPos((int)stage.MapData.get(0).get(i).x / 60, (int)stage.MapData.get(0).get(i).y / 56)) {
								if(stage.MapData.get(0).get(i).current == 0) {
									stage.MapData.get(0).get(i).move = Const.DEAD;
									if(StageNum < 11 || StageNum > 25) stage.MapData.get(0).get(i).current = 1;									
								}
							}	
						}
					} else if(stage.MapData.get(0).get(i).move == Const.DEAD) {
						stage.MapData.get(0).get(i).show = false;
					}
					
					if(!left_right) gInfo.ScrollY = stage.MapData.get(0).get(i).y - 240;
					if((StageNum >= 11 && StageNum <= 14) || (StageNum >= 21 && StageNum <= 25)) gInfo.ScrollX = stage.MapData.get(0).get(i).x - 400 ;
					
				}			
			}

		}
		if(gInfo.ScrollY >= stage.MapScrollY - gInfo.ScreenY) gInfo.ScrollY = stage.MapScrollY - gInfo.ScreenY;  // 아래 땅이 고정 되게 하기 위해서
		if(gInfo.ScrollY <= 0) gInfo.ScrollY = 1;  // 윗의  땅이 고정 되게 하기 위해서
		if(gInfo.ScrollX <= 0 && (StageNum > 10 && StageNum < 26)) gInfo.ScrollX = 0;  // 아래 땅이 고정 되게 하기 위해서
		if((StageNum >= 11 && StageNum <= 25) && gInfo.ScrollX >= stage.MapScrollX - gInfo.ScreenX) gInfo.ScrollX = stage.MapScrollX - gInfo.ScreenX; 
		
	}
 	
 	private void  UpdateMapStage()
 	{
 		boolean bok = false;
 		if(Tifo.mTifoList != null) {
 			if(Tifo.mTifoList.size() > 0) {
 	 			long tmp = Long.valueOf((String)Tifo.mTifoList.get(0).get("time"));
 	 			int as = (int)((System.currentTimeMillis()-tmp) / 1000); 
// 	 			System.out.println("tmp = " + tmp);
 	 			if(as >= 600) {
 	 				bok = true;
 	 			}
 			} else {
 				bok = true;
 			}
 		} else {
 			bok = true;
 		}
 		
 		bok = true;   ///  임시(기다림 여부) 

 		if(bok) {
 			for (int i = 0; i < MapButton.size(); i++ )
 			{
 				if ( MapButton.get(i).current == 0) {
 					if ( MapButton.get(i).click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
 	 				{
 	 					GameMode = 4;
 	 					MapButton.get(i).ResetButton();
 	 					start = map_range[i][0];
 	 					end   = map_range[i][1];
 	 					
 	 					LoadIntroData();
 	 				}
 				}
  			}	
 		} else {
 			/// 5분 이후에 가능합니다 
 		}
 		
 	}
	
 	
 	private void  UpdateStage()
 	{
		for (int i = 0; i < Button.size(); i++ )
		{
			if ( Button.get(i).current == 0) {
				if ( Button.get(i).click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
				{
//					GameMode = 5;
					motion = MyRand.nextInt(4);
					f = 0;
					GameMode = 86;
					Button.get(i).ResetButton();
	        		StageNum = i + start;
	        		bGameOver = true;
				}
			} else if ( Button.get(i).current == 1) {
				if ( Button.get(i).click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
				{
					Button.get(i).ResetButton();
				}
			}
		}	
 	}
 	
 	private void  UpdateApply()
 	{
		for (int i = 0; i < LawButton.size(); i++ )
		{
			if ( LawButton.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
				if ( LawButton.get(i).click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
				{
					Tifo.goLaw();
					LawButton.get(i).ResetButton();
				}
			}
		}	

		for (int i = 0; i < ApplyButton.size(); i++ )
		{
			if ( ApplyButton.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
				if ( ApplyButton.get(i).click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
				{
					ApplyButton.get(i).motion = 3;
					Tifo.requestEnableConnection();
					ApplyButton.get(i).ResetButton();
						
				}
			}
		}	
		
 	}	
 	
 	private void updateQuitUI(int gameMode) {
 		QuitUI.Draw( mGL, gInfo, null ); // 등록한 모든 UI를 화면에 그려준다.
		for ( int i = 0; i < QuitUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if ( QuitUI.UIList.get(i).index == UIQuitClass.Group0.ONE_CLICK_002 ) 
			{
				if ( QuitUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( QuitUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						QuitUI.UIList.get(i).ResetButton();
						System.exit(0);
					}
				}
			}
			
			if ( QuitUI.UIList.get(i).index == UIQuitClass.Group0.ONE_CLICK_003 )
			{
				if ( QuitUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( QuitUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						if(gameMode == 3) {
							GameMode = 3;
							bGameOver = false;
						} else {
							GameMode = 91;
						}
						
						QuitUI.UIList.get(i).ResetButton();
						QuitUI.DeleteLastGroup( gInfo );
						QuitUI.AddDialogGroup( 0, 0, 0.3f );
					}
				}
			}
		}
 	}
 	private void updateNoticeUI() {
		NoticeUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.
		for ( int i = 0; i < NoticeUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if ( NoticeUI.UIList.get(i).index == UINoticeClass.Group0.ONE_CLICK_002 ) 
			{
				if ( NoticeUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( NoticeUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						Tifo.goUrl();
						NoticeUI.UIList.get(i).ResetButton();
					}
				}
			}

				
			if ( NoticeUI.UIList.get(i).index == UINoticeClass.Group0.ONE_CLICK_003 )
			{
				if ( NoticeUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( NoticeUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						GameMode = 91;
						
						NoticeUI.UIList.get(i).ResetButton();
//						MainUI.DeleteLastGroup( gInfo );
//						MainUI.AddGroup( 2, 2 );
					}
				}
			}
		}
 	}
 	
 	private void updateFriendRankingUI() {
  		FriendRankingUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.
 		for( int i = 0; i < RankingButton.size(); i++) RankingButton.get(i).DrawSprite(mGL, 0, gInfo, font);
 		for( int i = 0; i < RankingSendButton.size(); i++) {
			if(Tifo.mFriendRanking.get(i).get("messageYn").equals("Y") && Tifo.mFriendRanking_Btn[i].equals("")) {  // 메세지 전송 동의 여부 
				RankingSendButton.get(i).DrawSprite(mGL, 0, gInfo, font);
			}
 		}
		for ( int i = 0; i < FriendRankingUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if ( FriendRankingUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
				if ( FriendRankingUI.UIList.get(i).index == UIFriendRankingClass.Group0.ONE_CLICK_006 )     // 게임 start
				{
					if ( FriendRankingUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						if(tifoCount <= 0) {
							bStart = true;
							updateAlterUI("게임 할수 있는 티포 수가 없습니다.", 91, FriendRankingUI.UIList.get(i));
						} else {
							LoadMapData();
							FriendRankingUI.UIList.get(i).ResetButton();
						}
					}
				}
				if ( FriendRankingUI.UIList.get(i).index == UIFriendRankingClass.Group0.ONE_CLICK_007 )  // 환경설정
				{
					if ( FriendRankingUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						GameMode = 92;	
							
						FriendRankingUI.UIList.get(i).ResetButton();
					}
				}
				if ( FriendRankingUI.UIList.get(i).index == UIFriendRankingClass.Group0.ONE_CLICK_008 )  // 상점 
				{
					if ( FriendRankingUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						GameMode = 94;	
							
						FriendRankingUI.UIList.get(i).ResetButton();
					}
				}
				if ( FriendRankingUI.UIList.get(i).index == UIFriendRankingClass.Group0.ONE_CLICK_009 )  // 사이버머니  
				{
					if ( FriendRankingUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						GameMode = 95;	
							
						FriendRankingUI.UIList.get(i).ResetButton();
					}
				}
				if ( FriendRankingUI.UIList.get(i).index == UIFriendRankingClass.Group0.ONE_CLICK_010 )  // 친구초대
				{
					if ( FriendRankingUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						GameMode = 93;
						FriendRankingUI.UIList.get(i).ResetButton();
					}
				}
				if ( FriendRankingUI.UIList.get(i).index == UIFriendRankingClass.Group0.ONE_CLICK_013 )  // 도움말 
				{
					if ( FriendRankingUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						GameMode = 84;
						FriendRankingUI.UIList.get(i).ResetButton();
					}
				}
			}
		}
		
		for (int i = 0; i < RankingSendButton.size(); i++ )
		{
			if ( RankingSendButton.get(i).type == ButtonType.TYPE_ONE_CLICK )  {
				if ( RankingSendButton.get(i).click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
				{
					RankingSendButton.get(i).ResetButton();
					if(Tifo.mFriendRanking.get(i).get("messageYn").equals("Y") && Tifo.mFriendRanking_Btn[i].equals("")) {  // 메세지 전송 동의 여부 
//						Tifo.sendGameMessageToPbFriend(Tifo.mFriendRanking.get(i).get("id"), Tifo.mFriendRanking.get(i).get("mdn"), Tifo.mFriendRanking.get(i).get("ranking"));
						Tifo.setCompen(MainContext, Tifo.mFriendRanking.get(i).get("id"), Tifo.mFriendRanking.get(i).get("mdn"), Tifo.mFriendRanking.get(i).get("ranking"));
						Tifo.mFriendRanking_Btn[i] = "Y";
					} 
				}
			}
		}
 	}
 	private void updateSettingUI() {
 		SettingUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.
		for ( int i = 0; i < SettingUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if ( SettingUI.UIList.get(i).index == UISettingClass.Group0.ONE_CLICK_001 )     
			{
				if ( SettingUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( SettingUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )   // background sound
					{
						if(Tifo.back_sound.equals("Y")) {
						    SettingUI.UIList.get(i).motion = 3;
						    Tifo.back_sound = "N";
						    Back_Music.pause();
						} else {
						    SettingUI.UIList.get(i).motion = 1;
						    Tifo.back_sound = "Y";
						    Back_Music.start();
		 				}
						SettingUI.UIList.get(i).ResetButton();
						Tifo.setSettingData(MainContext, "", "", Tifo.back_sound);
					}
				}
			}

				
			if ( SettingUI.UIList.get(i).index == UISettingClass.Group0.ONE_CLICK_002 )  // effect sound
			{
				if ( SettingUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( SettingUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						if(Tifo.effect_sound.equals("Y")) {
						    SettingUI.UIList.get(i).motion = 4;
						    Tifo.effect_sound = "N";
			 			} else { 
						    SettingUI.UIList.get(i).motion = 2;
						    Tifo.effect_sound = "Y";
			 		    }	
						SettingUI.UIList.get(i).ResetButton();
						Tifo.setSettingData(MainContext, "", Tifo.effect_sound, "");
					}
				}
			}
			if ( SettingUI.UIList.get(i).index == UISettingClass.Group0.ONE_CLICK_003 )  // close
			{
				if ( SettingUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( SettingUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )
					{
						GameMode = 91;	
						SettingUI.UIList.get(i).ResetButton();
					}
				}
			}
		}
 	}
 
 	private void updateFriendInVitUI() {
 		Friend_InVitUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.
 		for( int i = 0; i < InVitButton.size(); i++) InVitButton.get(i).DrawSprite(mGL, 0, gInfo, font);
 		for( int i = 0; i < InVitSendButton.size(); i++) {
			if(Tifo.mFriendInVit.get(i).get("Invitation").equals("Y") && Tifo.mFriendInVit.get(i).get("invited").equals("N") && Tifo.mFriendInVit_Btn[i].equals("")) {  // 메세지 전송 동의 여부 
				InVitSendButton.get(i).DrawSprite(mGL, 0, gInfo, font);
			}
 		}
		for ( int i = 0; i < Friend_InVitUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			
			
			if ( Friend_InVitUI.UIList.get(i).index == UIFriend_InVitClass.Group0.POPUP_000 )   
			{
				Friend_InVitUI.UIList.get(i).SetText(0, 20, 18, 0, 0, 0, 13, "친구는 안드로이드 단말기만 가능합니다.");
			}
			if ( Friend_InVitUI.UIList.get(i).index == UIFriend_InVitClass.Group0.ONE_CLICK_002 )     
			{

				if ( Friend_InVitUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( Friend_InVitUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )   
					{
						
						GameMode = 91;
						Friend_InVitUI.UIList.get(i).ResetButton();
						Friend_InVitUI.DeleteLastGroup( gInfo );
						Friend_InVitUI.AddDialogGroup( 0, 0, 0.3f );
						DataSetFriendInVit();
					}
				}
			}
		}
		for (int i = 0; i < InVitSendButton.size(); i++ )
		{
			if ( InVitSendButton.get(i).click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
			{
				if(Tifo.mFriendInVit.get(i).get("Invitation").equals("Y") && Tifo.mFriendInVit.get(i).get("invited").equals("N") && Tifo.mFriendInVit_Btn[i].equals("")) {  // 메세지 전송 동의 여부 
					Tifo.sendInviteMessageToPbFriend(Tifo.mFriendInVit.get(i).get("id"), Tifo.mFriendInVit.get(i).get("mdn"));
					InVitSendButton.get(i).ResetButton();
					Tifo.mFriendInVit_Btn[i] = "Y";
				} 
			}
		}
	}

	private void updateTimeBuyUI() {
 		TimeBuyUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.

 		
		for ( int i = 0; i < TimeBuyUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if(TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.POPUP_000) {
				TimeBuyUI.UIList.get(i).SetText(0, 20, 390, 0, 0, 0, 15, "스테이즈 게임시간을 구매(영구적/기본2분)", 300, 60);
			}
			if(TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.POPUP_002) {
				TimeBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 1분 = 1,000원", 100, 60);
			} else if(TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.POPUP_003) {
				TimeBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 2분 = 2,000원", 100, 60);
			} else if(TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.POPUP_004) {
				TimeBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 3분 = 3,000원", 100, 60);
			} else if(TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.POPUP_005) {
				TimeBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 4분 = 4,000원", 100, 60);
			} else if(TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.POPUP_006) {
				TimeBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 5분 = 5,000원", 100, 60);
			} else if(TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.POPUP_007) {
				TimeBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 6분 = 6,000원", 100, 60);
			}
			if ( TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.ONE_CLICK_014 )  // close     
			{

				if ( TimeBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TimeBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						
						GameMode = 91;
						TimeBuyUI.UIList.get(i).ResetButton();
						TimeBuyUI.DeleteLastGroup( gInfo );
						TimeBuyUI.AddDialogGroup( 0, 0, 0.3f );
					}
				}
			}
			if ( TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.ONE_CLICK_008 )  // 1000     
			{

				if ( TimeBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TimeBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						TimeBuyUI.UIList.get(i).ResetButton();
						Tifo.callPayment(Tifo.PID_1);
					}
				}
			}
			if ( TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.ONE_CLICK_009 )  // 2000     
			{

				if ( TimeBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TimeBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						TimeBuyUI.UIList.get(i).ResetButton();
						Tifo.callPayment(Tifo.PID_2);
					}
				}
			}
			if ( TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.ONE_CLICK_010 )  // 3000     
			{

				if ( TimeBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TimeBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						TimeBuyUI.UIList.get(i).ResetButton();
						Tifo.callPayment(Tifo.PID_3);
					}
				}
			}
			if ( TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.ONE_CLICK_011 )  // 4000     
			{

				if ( TimeBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TimeBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						TimeBuyUI.UIList.get(i).ResetButton();
						Tifo.callPayment(Tifo.PID_4);
					}
				}
			}
			if ( TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.ONE_CLICK_012 )  // 5000     
			{

				if ( TimeBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TimeBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						
						TimeBuyUI.UIList.get(i).ResetButton();
						Tifo.callPayment(Tifo.PID_5);
					}
				}
			}
			if ( TimeBuyUI.UIList.get(i).index == UITimeBuyClass.Group0.ONE_CLICK_013 )  // 6000     
			{

				if ( TimeBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TimeBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						
						TimeBuyUI.UIList.get(i).ResetButton();
						Tifo.callPayment(Tifo.PID_6);
					}
				}
			}
		}

	}
	
	private void updateTifoBuyUI() {
 		TifoBuyUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.

 		
		for ( int i = 0; i < TifoBuyUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if(TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.POPUP_000) {
				TifoBuyUI.UIList.get(i).SetText(0, 33, 380, 0, 0, 0, 16, "티포 수를 구매 (일회 사용/소멸형)", 240, 60);
			}
			if(TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.POPUP_002) {
				TifoBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 1명 = 1,000점", 100, 60);
			} else if(TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.POPUP_003) {
				TifoBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 2명 = 2,000점", 100, 60);
			} else if(TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.POPUP_004) {
				TifoBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 3명 = 3,000점", 100, 60);
			} else if(TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.POPUP_005) {
				TifoBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 4명 = 4,000점", 100, 60);
			} else if(TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.POPUP_006) {
				TifoBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 5명 = 5,000점", 100, 60);
			} else if(TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.POPUP_007) {
				TifoBuyUI.UIList.get(i).SetText(0, 55, 120, 0, 0, 0, 13, "x 6명 = 6,000점", 100, 60);
			}
			if ( TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.ONE_CLICK_014 )  // close     
			{

				if ( TifoBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TifoBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						
						GameMode = 91;
						TifoBuyUI.UIList.get(i).ResetButton();
						TifoBuyUI.DeleteLastGroup( gInfo );
						TifoBuyUI.AddDialogGroup( 0, 0, 0.3f );
					}
				}
			}
			if ( TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.ONE_CLICK_008 )  // 1000     
			{

				if ( TifoBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TifoBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						if(hartNum < 1000) {
							updateAlterUI("현재 하트가 " + hartNum + "점 라서 구매할수 없습니다" , 95, TifoBuyUI.UIList.get(i));
						} else {
							TifoBuyUI.UIList.get(i).ResetButton();
							Tifo.setTifoBuy(hartNum - 1000, tifoCount+1,  1000);
						}						
					}
				}
			}
			if ( TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.ONE_CLICK_009 )  // 2000     
			{

				if ( TifoBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TifoBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						if(hartNum < 2000) {
							updateAlterUI("현재 하트가 " + hartNum + "점 라서 구매할수 없습니다" , 95, TifoBuyUI.UIList.get(i));
						} else {
							TifoBuyUI.UIList.get(i).ResetButton();
							Tifo.setTifoBuy(hartNum - 2000, tifoCount+2,  2000);
						}						
					}
				}
			}
			if ( TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.ONE_CLICK_010 )  // 3000     
			{

				if ( TifoBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TifoBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						if(hartNum < 3000) {
							updateAlterUI("현재 하트가 " + hartNum + "점 라서 구매할수 없습니다" , 95, TifoBuyUI.UIList.get(i));
						} else {
							TifoBuyUI.UIList.get(i).ResetButton();
							Tifo.setTifoBuy(hartNum - 3000, tifoCount+3,  3000);
						}						
					}
				}
			}
			if ( TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.ONE_CLICK_011 )  // 4000     
			{

				if ( TifoBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TifoBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						if(hartNum < 4000) {
							updateAlterUI("현재 하트가 " + hartNum + "점 라서 구매할수 없습니다" , 95, TifoBuyUI.UIList.get(i));
						} else {
							TifoBuyUI.UIList.get(i).ResetButton();
							Tifo.setTifoBuy(hartNum - 4000, tifoCount+4,  4000);
						}						
					}
				}
			}
			if ( TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.ONE_CLICK_012 )  // 5000     
			{

				if ( TifoBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TifoBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						if(hartNum < 5000) {
							updateAlterUI("현재 하트가 " + hartNum + "점 라서 구매할수 없습니다" , 95, TifoBuyUI.UIList.get(i));
						} else {
							TifoBuyUI.UIList.get(i).ResetButton();
							Tifo.setTifoBuy(hartNum - 5000, tifoCount+5,  5000);
						}						
					}
				}
			}
			if ( TifoBuyUI.UIList.get(i).index == UITifoBuyClass.Group0.ONE_CLICK_013 )  // 6000     
			{

				if ( TifoBuyUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( TifoBuyUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						if(hartNum < 6000) {
							updateAlterUI("현재 하트가 " + hartNum + "점 라서 구매할수 없습니다" , 95, TifoBuyUI.UIList.get(i));
						} else {
							TifoBuyUI.UIList.get(i).ResetButton();
							Tifo.setTifoBuy(hartNum - 6000, tifoCount+6,  6000);
						}						
					}
				}
			}
		}

	}	
	
	private void updateResultUI() {
 		ResultUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.

		for ( int i = 0; i < ResultUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if ( ResultUI.UIList.get(i).index == UIResultClass.Group0.ONE_CLICK_006 )  // close     
			if ( ResultUI.UIList.get(i).index == UIResultClass.Group0.ONE_CLICK_006 )  // close     
			{

				if ( ResultUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( ResultUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						Tifo.setResult(totalNum, pointNum, currentLevel, hartNum);
						
						GameMode = 91;
						fanfare = false;
						ResultUI.UIList.get(i).ResetButton();
						ResultUI.DeleteLastGroup( gInfo );
						ResultUI.AddDialogGroup( 0, 0, 0.3f );
					}
				}
			}
		}
	}	
 	private void  UpdateTimeOver()
 	{
//		if ( TimeOverButton.type == ButtonType.TYPE_ONE_CLICK )  {
//			if ( TimeOverButton.click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
//			{
//				if(Target != null)  Target.move = Const.DEAD;
//				Target.dead = true;
//				bGameOver = true;					
//				tifoCount--;
//				if(tifoCount <= 0) {
//					//
//				} else {
//					pointNum = pre_pointNum;
//					hartNum  = pre_hartNum;
//				}
//
//				TimeOverButton.ResetButton();
//				OverButton.ResetButton();
//	 		}	
//		}
		
		if ( OverButton.type == ButtonType.TYPE_ONE_CLICK )  {
			if ( OverButton.click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
			{
				if(Target != null)  Target.move = Const.DEAD;
				Target.dead = true;
				bGameOver = true;					
				tifoCount--;
				motion = MyRand.nextInt(4);
				f = 0;

				if(tifoCount <= 0) {
					//
				} else {
					pointNum = pre_pointNum;
					hartNum  = pre_hartNum;
				}

				TimeOverButton.ResetButton();
				OverButton.ResetButton();
	 		}	
		}
		
		
 	}
 	private void  UpdateGameOver()
 	{
//		if ( GameOverButton.type == ButtonType.TYPE_ONE_CLICK ) {
//			if ( GameOverButton.click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
//			{
//				if(Target != null) {
//					Target.dead = true;
//					Target.move = Const.DEAD;
//				}
//				bGameOver = true;					
//				tifoCount--;
//				if(tifoCount <= 0) {
//					//
//				} else {
//					pointNum = pre_pointNum;
//					hartNum  = pre_hartNum;
//				}
//				dead = false;
//				GameOverButton.ResetButton();
//				OverButton.ResetButton();
//	 		}	
//		}
		if ( OverButton.type == ButtonType.TYPE_ONE_CLICK ) {
			if ( OverButton.click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
			{
				if(Target != null) {
					Target.dead = true;
					Target.move = Const.DEAD;
				}
				bGameOver = true;					
				tifoCount--;
				if(tifoCount <= 0) {
					//
				} else {
					pointNum = pre_pointNum;
					hartNum  = pre_hartNum;
				}
				over = false;
				dead = false;
				GameOverButton.ResetButton();
				OverButton.ResetButton();
	 		}	
		}		
 	}
	public void updateAlterUI(String message, int gameMode, ButtonObject bt) {
		AlterUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.

 		
		for ( int i = 0; i < AlterUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if ( AlterUI.UIList.get(i).index == UIAlertClass.Group0.POPUP_000)       
			{
				AlterUI.UIList.get(i).SetText(0, 130, 180, 0, 0, 0, 20, message, 400, 80);
			} else if ( AlterUI.UIList.get(i).index == UIAlertClass.Group0.ONE_CLICK_001)  // close     
			{

				if ( AlterUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( AlterUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						if(gameMode == 99) {
							System.exit(0);
						} else {
							GameMode = gameMode;
						}
						AlterUI.UIList.get(i).ResetButton();
						AlterUI.DeleteLastGroup( gInfo );
						AlterUI.AddDialogGroup( 0, 0, 0.3f );
						
						if(bt != null) {
							bStart = false;
							bt.ResetButton();
						}
					}
				}
			}
		}
	}	
	
	private void updateDataChkUI() {
		DataChkUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.

		for ( int i = 0; i < DataChkUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if ( DataChkUI.UIList.get(i).index == UIDataChkClass.Group0.POPUP_000 ) {
				DataChkUI.UIList.get(i).SetText(0, 120, 70, 0, 0, 0, 16, "3G,LTE 연결시 가입하신 요금제에 따라 데이터 통화료가 발생 할 수 있습니다. (LTE의 경우 LTE단말에 한함) 동의하시면 OK, 아니면 CLOSE", 380, 200);
			}
			if ( DataChkUI.UIList.get(i).index == UIDataChkClass.Group0.ONE_CLICK_001 )  // ok     
			{

				if ( DataChkUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( DataChkUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						Tifo.setDataChk();
	
						DataChkUI.UIList.get(i).ResetButton();
						DataChkUI.DeleteLastGroup( gInfo );
						DataChkUI.AddDialogGroup( 0, 0, 0.3f );
					}
				}
			}
			if ( DataChkUI.UIList.get(i).index == UIDataChkClass.Group0.ONE_CLICK_002 )  // close     
			{

				if ( DataChkUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( DataChkUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						DataChkUI.UIList.get(i).ResetButton();
						System.exit(0);
					}
				}
			}
		}
	}
	
	private void updateLoginUI() {
		LoginUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.

		for ( int i = 0; i < LoginUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if ( LoginUI.UIList.get(i).index == ULoginClass.Group0.POPUP_000 ) {
				LoginUI.UIList.get(i).SetText(0, 330, 95, 0, 0, 0, 30, "티포의 모험", 200, 40);
				LoginUI.UIList.get(i).SetText(1, 40, 220, 0, 0, 0, 17, "이 게임은 회원님의 T store 닉네임, 친구목록 등의 개인 정보를 사용할 수 있습니다. T store 친구목록은 폰북 친구중 T store 해당  게임 이용자를 말하여 그 외 친구를 게임에 초대할 수도 있습니다. 친구 초대 시와 게임 내에서 친구 간에 주고 받는 메시지를 보낼때에는 (SMS, AOM)가 수신됩니다. \n\n동의하시면 T store는 이 정보를 해당 앱 개발자/개발업체에 제공하게 되며, 해당 앱에서는 회원님의 앱 사용시 이를 보유하게 됩니다. \n\nT store회원이 아닌 경우 T store 회원가입부터 진행됩니다.", 700, 300);
			}
			if ( LoginUI.UIList.get(i).index == ULoginClass.Group0.ONE_CLICK_002 )  // ok     
			{

				if ( LoginUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( LoginUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						Tifo.requestEnableConnection();						
						
						LoginUI.UIList.get(i).ResetButton();
						LoginUI.DeleteLastGroup( gInfo );
						LoginUI.AddDialogGroup( 0, 0, 0.3f );
					}
				}
			}
			if ( LoginUI.UIList.get(i).index == ULoginClass.Group0.ONE_CLICK_003 )  // close     
			{

				if ( LoginUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( LoginUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						LoginUI.UIList.get(i).ResetButton();
						System.exit(0);
					}
				}
			}
		}
	}	
	private void updateHelpUI() {
		HelpUI.Draw( mGL, gInfo, font ); // 등록한 모든 UI를 화면에 그려준다.

		for ( int i = 0; i < HelpUI.UIList.size(); i++ ) // 모든 UI의 버튼 터치 상태를 체크하기 위한 루프
		{
			if ( HelpUI.UIList.get(i).index == ULoginClass.Group0.POPUP_000 ) {
				HelpUI.UIList.get(i).SetText(0, 430, 80, 0, 0, 0, 20, "게임 상에 하트를 먹으면 5점, 친구초대 메시지를 보내면 30점, 친구에게 랭킹 점수를 보내면 10점을 충전", 300, 300);
				HelpUI.UIList.get(i).SetText(1, 430, 175, 0, 0, 0, 20, "스테이즈별 기본시간은 2분이 주어지고, 넘어가면 TimeOver, 시간은 상점에서 충전가능하면 영구적 사용", 300, 300);
				HelpUI.UIList.get(i).SetText(2, 430, 270, 0, 0, 0, 20, "티포는 기본 5마리 주어지고, 하트 점수로 티포를 구매, 일회성으로 사용", 300, 300);
			}
			if ( HelpUI.UIList.get(i).index == UIHelpClass.Group0.ONE_CLICK_008 )  // ok     
			{

				if ( HelpUI.UIList.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
					if ( HelpUI.UIList.get(i).click == ButtonType.STATE_CLK_BUTTON )  
					{
						GameMode = 91;
						HelpUI.UIList.get(i).ResetButton();
						HelpUI.DeleteLastGroup( gInfo );
						HelpUI.AddDialogGroup( 0, 0, 0.3f );
					}
				}
			}
		}
	}	
	
	public void DoGame()
	{
		synchronized (mGL)
		{
			font.BeginFont(gInfo);
//			Moving = false;
			if(GameMode == -1) {   // t-store 회사로고
				t_store.PutAni( gInfo, 400, 240, 0, 0 );
				copywrite.PutAni( gInfo, 400, 440, 0, 0 );
				if(StartTimer == 0) {
					StartTimer = System.currentTimeMillis();
				}
				int as = (int)((System.currentTimeMillis()-StartTimer) / 1000);
				if(as >= 1) {
					GameMode = 0;
					StartTimer = 0;
				}
			} else if(GameMode == 0) {   // 회사로고
				com_logo.PutAni( gInfo, 400, 240, 0, 0 );
				if(StartTimer == 0) {
					StartTimer = System.currentTimeMillis();
					//gInfo.Fade = 0.0008f;
				}
	    		//gInfo.Fade += 0.04f;
	    		//if ( gInfo.Fade > 1.0f ) gInfo.Fade = 1.0f;
				int as = (int)((System.currentTimeMillis()-StartTimer) / 1000);
//				if(as >= 1) {
					StartTimer = 0;
					GameMode = 1;
//				}
			} else if(GameMode == 1) {   // 게임스토리 
				LoadCartoon();
				cartoon.PutAni( gInfo, 400, 240, 0, 0 );
				if(StartTimer == 0) {
					StartTimer = System.currentTimeMillis();
					LoadTimeBuy();
					LoadTifoBuy();
					LoadResult();
					LoadCartoonButton();
					LoadHelp();
	                Message m = new Message();
	                m.obj = "7";
					Tifo.mHandler.sendMessage(m);
//					Tifo.getVersion();
				}

				for (int i = 0; i < SkipButton.size(); i++ ) SkipButton.get(i).DrawSprite(mGL, 0, gInfo, font); // 이펙트 등으로 추가된 오브젝트들을 그려준다.
				for (int i = 0; i < NextButton.size(); i++ ) NextButton.get(i).DrawSprite(mGL, 0, gInfo, font); // 이펙트 등으로 추가된 오브젝트들을 그려준다.
				for (int i = 0; i < SkipButton.size(); i++ )
				{
					if ( SkipButton.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
						if ( SkipButton.get(i).click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
						{
							LoadGameMain();
							
							GameMode = 97;
							StartTimer = 0;
							SkipButton.get(i).ResetButton();
						}
					}
				}	

				for (int i = 0; i < NextButton.size(); i++ )
				{
					if ( NextButton.get(i).type == ButtonType.TYPE_ONE_CLICK ) {
						if ( NextButton.get(i).click == ButtonType.STATE_CLK_BUTTON ) // 버튼이 눌린 경우
						{
							CartoonNum++;
							if(CartoonNum >= 4) {
								LoadGameMain();
		
								GameMode = 97;
								StartTimer = 0;
							}							
							NextButton.get(i).ResetButton();
								
						}
					}
				}					
				
			} else if(GameMode == 2) {  //  메인화면 
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				
				if(Tifo.APPLY_STATUS == Tifo.STATUS_DISABLE_CONNECTION) {
//					apply.PutAni( gInfo, 400, 400, 2, 0 );
//					UpdateApply();
//					for (int i = 0; i < LawButton.size(); i++ ) LawButton.get(i).DrawSprite(mGL, 0, gInfo, font); // 이펙트 등으로 추가된 오브젝트들을 그려준다.
//					for (int i = 0; i < ApplyButton.size(); i++ ) ApplyButton.get(i).DrawSprite(mGL, 0, gInfo, font); // 이펙트 등으로 추가된 오브젝트들을 그려준다.
					
					updateLoginUI();
				} else if(Tifo.APPLY_STATUS == Tifo.STATUS_NO_MEMBER) {
					// T-Store 회원이 아닌 경우
					if(invokeTstoreJoinPage == false) {
						invokeTstoreJoinPage = true;
						Tifo.invokeTstoreJoinPage();
					}
				} else if(Tifo.APPLY_STATUS == 9) {
					// 정상 
//					if(notice == false) {
//						notice = true;
//						Tifo.getNotice();
//					}
					GameMode = 85;
				}
				
		 		if(StartTimer == 0) {
					StartTimer = System.currentTimeMillis();
				}
			} else if(GameMode == 3) {  // 
//				LoadGameMain();
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				key.PutAni( gInfo, 400, 240, 0, 0 );
				UpdateMapStage();
				
				if(MapButton != null) for (int i = 0; i < MapButton.size(); i++ ) MapButton.get(i).DrawSprite(mGL, 0, gInfo, font); // 이펙트 등으로 추가된 오브젝트들을 그려준다.
				
			} else if(GameMode == 4) {  // 
//				LoadGameMain();
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				key.PutAni( gInfo, 400, 240, 0, 0 );


				UpdateStage();
				for (int i = 0; i < Button.size(); i++ ) Button.get(i).DrawSprite(mGL, 0, gInfo, font); // 이펙트 등으로 추가된 오브젝트들을 그려준다.
			} else if(GameMode == 84) {  // 도움말 
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				
				updateHelpUI();
				
			} else if(GameMode == 85) {  // 데이터 동의 
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				
				if(!Tifo.getDataChk()) {
					updateDataChkUI();
				} else {
					GameMode = 88;
				}
				
			} else if(GameMode == 86) {  // process
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				key.PutAni( gInfo, 400, 240, 0, 0 );
				f += 0.2f;
				boolean load = false;
				family.PutAniReal(gInfo, 420, 190, motion, (int)f);
				if(f > 6) {
					f = 0;
					GameMode = 5;
				}
				
			} else if(GameMode == 87) {  // 버전 호출 
				if(version == false) {
					version = true;
					Tifo.callTStore();
				}
			} else if(GameMode == 88) {  // 공지사항 호출 
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				if(notice == false) {
					notice = true;
					Tifo.getNotice();
				}
			} else if(GameMode == 89) {  // 가족상봉
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				LoadFamilyMeet();
				if(StartTimer == 0) {
					StartTimer = System.currentTimeMillis();
					//gInfo.Fade = 0.0008f;
				}				
				fy_meet_bk.PutAni( gInfo, 400, 240, 0, 0 );
				fy_meet.PutAni( gInfo, 300, 360, 0, 0 );
				int as = (int)((System.currentTimeMillis()-StartTimer) / 1000);
				if(as >= 2) {
					FamilyNum++;
					StartTimer = 0;					
					if(FamilyNum >= 3) {
						StartTimer = 0;
						GameMode = 96;
					}
				}				
			} else if(GameMode == 90) {  // 공지사항
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				if(bNotice == false) {
					bNotice = true;
					LoadNoticeUI();
				}
		 		updateNoticeUI();
			} else if(GameMode == 91) {  // 친구순위 
				if(bFriendRanking == false) {
					Tifo.requestPBInviteTargetList();
					bFriendRanking = true;
				}
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				if(requestPBFriendRankingList) {
					LoadWeekRanking();
					requestPBFriendRankingList = false;
				}	
				updateFriendRankingUI();
				if(bStart == false) {
					PutValue( tifoCount, 590, 150, Point, 17, 20 );   // 티포 목숨 갯수 
					PutValue( timeCount, 695, 200, Point, 17, 30 );   // 시간 갯수 
				}
				PutValue( hartNum, 715, 150, Point, 17, 20 );     // 하트점수  
				
			} else if(GameMode == 92) {  // 환경설정  
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				updateSettingUI();
			} else if(GameMode == 93) {  // 친구초대 
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				updateFriendInVitUI();
			} else if(GameMode == 94) {  // store(Time Buy)
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				updateTimeBuyUI();
			} else if(GameMode == 95) {  // Tifo Buy 
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				updateTifoBuyUI();
			} else if(GameMode == 96) {  // Result
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				
				if(Tifo.effect_sound.equals("Y") && fanfare == false) {
					Tifo.setSettingData(MainContext, System.currentTimeMillis()+"","","");
					PlaySound( 4 );
					fanfare = true;
					MakeFire( 200, 150, 30, true, 0 ); // 불꽃 이펙트 생성
					MakeFire( 400, 150, 40, true, 1 ); // 불꽃 이펙트 생성
					MakeFire( 700, 250, 20, true, 2 ); // 불꽃 이펙트 생성

					MakeFire( 100, 100, 50, true, 2 ); // 불꽃 이펙트 생성
					MakeFire( 300, 250, 50, true, 0 ); // 불꽃 이펙트 생성
					MakeFire( 600, 150, 30, true, 1 ); // 불꽃 이펙트 생성
					
				}
				updateResultUI();
				totalNum = pointNum + hartNum + currentLevel ;
				
				PutValue(pointNum, 420, 130, Point, 17, 30 );   // 게임점수
				PutValue(currentLevel,  420, 180, Point, 17, 30 );  // Level
				PutValue(hartNum, 420, 230, Point, 17, 30 );    // 하트점수
				PutValue(totalNum, 420, 290, Point, 17, 30 );   // Level
				updateEffect(Game);
	    		for (int i = 0; i < Game.size(); i++ ) Game.get(i).DrawSprite( gInfo ); // 이펙트 등으로 추가된 오브젝트들을 그려준다.
				
			} else if(GameMode == 97) {  // 인증첵크
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				if(!Tifo.isWifiConn && !Tifo.isMobileConn) {
					updateAlterUI("통신 불가 상태입니다. 휴대폰 상태를 점검하시고 다시 이용해 주세요", 99, null);
				} else {
					/** 
					 * 인증 요청
					 **/
					if(requestTstoreAuth == false) {
						Tifo.requestTstoreAuth();
						requestTstoreAuth = true;
					}
				}
			} else if(GameMode == 98) {  // alert
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				updateAlterUI(message, endJob, null);
			} else if(GameMode == 99) {  // 종료 
//				System.exit(0);
				gInfo.ScrollY = 0;
				gInfo.ScrollX = 0;
				gameMain_logo.PutAni( gInfo, 400, 240, 0, 0 );
				updateQuitUI(99);
	        } else  {
				if(bGameOver) {
					if(tifoCount <= 0) {    // 더이상 티포의 생명이 없을 때
						GameMode = 96;
					} else {
						LoadGameData();
					}
				} else {
			        UpdateGame();

					// 스테이지 번호에 해당하는 프로젝트 파일을 로딩하고 스프라이트는 Pattern에 오브젝트들은 temp에 저장시킨다.
					// 로딩한 오브젝트들의 총 개수를 리턴해 total에 저장한다.
					int as = (int)((System.currentTimeMillis()-StartGameTimer) / 1000);
					

			        stage.DrawObjectLayer(gInfo, 2);   // 바다 
		    		stage.DrawObjectLayer(gInfo, 3);   // 땅 
		    		stage.DrawObjectLayer(gInfo, 0);   //
		    		
		    		
		    		stage.DrawObjectLayer(gInfo, 1);   // 좌 우 숲 
		    		
		    		for (int i = 0; i < Game.size(); i++ ) Game.get(i).DrawSprite( gInfo ); // 이펙트 등으로 추가된 오브젝트들을 그려준다.

//		    		effect.PutAniReal( gInfo, 80, 40, 0, 0 ); // 배경 화면을 출력한다.
		    		score_ovr.PutAniReal( gInfo, 80, 40, 1, 0 ); // score 출력한다.
					PutValue( pointNum, 160, 25, Point, 17, 25 ); // 현재 스코어 표시

		    		result.PutAniReal( gInfo, 690, 40, 5, 0 );    // level 출력한다.
					PutValue(StageNum, 740, 25, Point, 17, 30 );  // stage 표시
					Point.PutAniReal(gInfo, 20, 420, 6, 0);
					Point.PutAniReal(gInfo, 80, 425, 15, 0);
					PutValue( tifoCount, 120, 425, Point, 17, 30 ); // 현재 티포의 갯수 
					
					item.PutAniReal(gInfo, 630, 420, 0, 4);       // 하트 
					PutValue(hartNum, 690, 420, Point, 17, 30 );  // 하트점수 

		    		if(Target != null) 	Target.DrawSprite(gInfo);
		    		
		    		if(as >= outtime) {
		    			over = true;
		    			UpdateTimeOver();
		    			OverButton.DrawSprite(mGL, 0, gInfo, font); 
		    			TimeOverButton.DrawSprite(mGL, 0, gInfo, font); 
		    		} else if(over){
		    			outtime = 999999999;
						if(Tifo.effect_sound.equals("Y") && dead == false) {
							PlaySound( 3 );
							dead = true;
						}
		    			UpdateGameOver();
		    			OverButton.DrawSprite(mGL, 0, gInfo, font); 
		    			GameOverButton.DrawSprite(mGL, 0, gInfo, font); 		    			
		    		}
		    		
				}
	        	
	        }


			font.EndFont(gInfo);
		}
	}
	
	public int PutValue( int val, int x, int y, Sprite pattern, int motion, int xsize )
	{
    	String str;
    	int i, num, len;
    	
    	str = String.format( "%d", val );
    	len = str.length();
    	
    	for ( i = 0; i < len; i++ )
    	{
    		num = (int)str.charAt(i) - '0';
    		pattern.PutAniReal( gInfo, x, y, motion, num );
    		x += xsize;
    	}
    	return x;
	}

}
